Get the QPixmap from a QLabel

Get the QPixmap from a QLabel

本文关键字:QLabel from QPixmap the Get      更新时间:2023-10-16

我有一个名为PictureQLabelPixmap已将其设置为QImage
我现在想在另一个函数中修改图像。
是否可以从Picture获得Pixmap

我尝试了以下操作,这会导致未处理的异常:

QPixmap const *pm = ui.Picture->pixmap();  
QImage image(pm->toImage());

还有其他办法吗?

我认为您应该检查pixmap()函数的返回值。

const QPixmap* pixmap = ui.Picture->pixmap();
if ( pixmap )
{
QImage image( pixmap->toImage() );
}

也许您只是在未设置图像时调用该函数,这导致了异常。