5

How to put an image on the GUI created by Qt? The south west part of the screen is empty so I want a picture to be put there on a click of a button but I am unable to use QPixmap and setPixmap. Please help me with this !

4

3 回答 3

11

在 Qt Creator 中使用 QLabel 然后转到 QLabel 的属性 转到 Pixmap 选择文件

完成。

于 2014-06-04T15:27:35.950 回答
3

您可以在要添加图像的地方创建 QWidget 或 QFrame。然后,您可以使用样式表在该图片上设置背景图像。您可能希望将图像添加到资源 (.qrc)。

对于此类任务,使用 QtDesigner 是一个好主意。

编辑:这是一种简单的方法,无需使用 QPixMap。

QWidget *frame = new QWidget(this);
frame->setGeometry(x, y, width, height);
frame->setStyleSheet("background-image: url(:/path/to/image.png)");

:指定您要使用 Qt 资源中的路径。如果QWidget使用 QtDesigner 定义,则不需要前两行。

另外,不要忘记导入您的resources.qrc(无论您如何称呼它)文件(包括您的资源)并将其添加到您的.pro

RESOURCES     = resources.qrc
于 2013-07-03T07:17:47.460 回答
2

您应该使用标签 ( QLabel)。您可以在表单中添加标签并pixmap在 Qt Designer 中编辑其属性(您将能够选择已添加到项目资源中的图像之一)。您还可以QLabel使用setPixmap().

于 2013-07-03T08:22:11.547 回答