问题描述
我创建了一个Qt界面,添加一个Qlabel并设置pixmap到一个图像。 imagelabel =
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")));
这是在使用Qtdesigner预览时显示在ui_mainwindow.h
中的代码,可以显示图像。但是当我运行使用代码块,一切像按钮等都很好,但图像不出现。我需要在下面的部分添加任何内容吗?
this is the code displayed in ui_mainwindow.hwhen i preview it using the Qtdesigner, the image can be displayed. But when i run using codeblocks, everything like buttons etc is 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
':'表示您正在尝试打开作为资源包含的图像。确保u有 .qrc
文件,并且它被添加到 .pro
项目文件中。喜欢:
":/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
同时确保该图像在 .qrc
文件中。
Also make sure that image is in the .qrc
file.
这篇关于在QLabel中显示图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!