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

来源:互联网 发布:知乎男生会刮腿毛吗 编辑:程序博客网 时间:2024/05/24 04:21
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); //加上这句就可以显示了!.


0 0
原创粉丝点击