从QLabel获取QPixmap [英] Get the QPixmap from a QLabel
本文介绍了从QLabel获取QPixmap的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 QLabel
调用图片
其中 Pixmap
已设置为 QImage
。
我现在要在另一个函数中修改图像。
可以获取图片
中的 Pixmap
?
I have a QLabel
called Picture
which Pixmap
has been set to a QImage
.
I now want to modify the image in another function.
Is it possible to get the Pixmap
from the Picture
?
我尝试下列操作,导致未处理的异常:
I tried the following, which results in an unhandled exception:
QPixmap const *pm = ui.Picture->pixmap();
QImage image(pm->toImage());
有没有其他方法?
推荐答案
我想你会检查 pixmap()
函数的返回值。
I think you shall check the return value of the pixmap()
function.
const QPixmap* pixmap = ui.Picture->pixmap();
if ( pixmap )
{
QImage image( pixmap->toImage() );
}
也许你只是在图像未设置时调用函数,例外。
Maybe you just called the function when the image was not set and that caused the exception.
这篇关于从QLabel获取QPixmap的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文