您的位置:首页 > 编程语言 > Qt开发

关于Qt中QLable显示图片的问题

2016-09-06 15:22 274 查看
mainwindow的构造函数中:
    QImage *ppm = new QImage(":/fanyingfu1");
    QLabel *label1 = new QLabel(this);
    label1->setPixmap(QPixmap::fromImage(*ppm));
    label1->setGeometry(100,100,40,40);

按钮单击槽函数中:
    QImage *ppm = new QImage(":/fanyingfu1");
    QLabel *label1 = new QLabel(this);
    label1->setPixmap(QPixmap::fromImage(*ppm));
    label1->setGeometry(100,100,40,40);

两段代码一样,但是在构造函数中写,可以显示图片,而在槽函数中写就不能显示图片。

.


MyLabel *pLabel = new MyLabel(parent);
QRect rect;
rect.setX(x);
rect.setY(y);
rect.setWidth(320);
rect.setHeight(300);
pLabel->setGeometry(rect);

px.load(":/new/prefix1/Resource/sam1.jpg");

pLabel->setPixmap(px);
pLabel->setScaledContents(true);
pLabel->setFrameStyle(QFrame::Panel | QFrame::Sunken); //设置外观
pLabel->setScaledContents(true);
pLabel->setVisible(true); //加上这句就可以显示了!

.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  图片