开发者

Displaying an image in QLabel

开发者 https://www.devze.com 2023-04-11 08:54 出处:网络
I have created a Qt interface, add a Qlabel and set pixmap to an image.imagelabel = new QLabel(centralwidget);

I have created a Qt interface, add a Qlabel and set pixmap to an image. imagelabel =

        new QLabel(centralwidget);
        imagelabel->setObjectName(QString::fromUtf8("imagelabel"));
        imagelabel->setGeometry(QRect(20, 10, 371, 311));
        imagelabel->setPixmap(QPixmap(QString::fromUtf8(":/liqi/kinect.png")));

this is the code displayed in ui_mainwindow.h when i preview it using the Qtdesigner, the image can be displayed. But when i run using codeblocks, everything like buttons etc i开发者_如何学运维s fine but the image does not appear. Do i need to add anything into the section below ?

    MainWindow::MainWindow(Tqt_interface* tqt, QWidget *parent ) : 
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

}


":/liqi/kinect.png" ':' means you are trying to open image that is included as resource. Make sure u have .qrc file and it is added in .pro project file. Like:

RESOURCES += res.qrc

Also make sure that image is in the .qrc file.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号