The Widget we should use to show pictures is a QLabel. we can do it directly from QtCreator, by setting its pixmap property.
我们应该用来显示图片的小部件是一个QLabel。我们可以通过设置它的pixmap属性直接从QtCreator中完成。
we should first create a resource file and then add the image to that resource file. To create a Qt Resource File, we go to the menus: File > Qt > Qt Resource File.
我们首先应该创建一个资源文件,然后将图像添加到该资源文件中。要创建Qt资源文件,我们进入菜单:File > Qt > Qt资源文件。
we can set the image of the QLabel using Qt Creator...
我们可以使用Qt创建者来设置QLabel的图像…
but i would want to change the pic according to some input from the user
但是我想根据用户的一些输入改变图片。
i tried to do the following :
我试着做以下的事情:
#include "form1.h"
#include "form.h"
#include "ui_form.h"
#include "ui_form1.h"
Form::Form(QWidget *parent) :
QWidget(parent),
ui(new Ui::Form)
{
ui->setupUi(this);
QPixmap * mypix = new QPixmap(":/karim/test.png");
ui->label->setPixmap(mypix);
delete mypix;
}
but i got this error
但我犯了这个错误。
..\Project\form.cpp: In constructor 'Form::Form(QWidget*)':
..\Project\form.cpp:12: error: no matching function for call to 'QLabel::setPixmap(QPixmap*&)'
c:\QtSDK\Simulator\Qt\mingw\include/QtGui/qlabel.h:123: note: candidates are: void QLabel::setPixmap(const QPixmap&)
what could be the problem ?
有什么问题吗?
1 个解决方案
#1
11
The signature of the method you are trying to use is
您要使用的方法的签名是。
setPixmap ( const QPixmap & )
setPixmap (const QPixmap &)
but you are passing in a pointer. Try using a value instead.
但是你在传递一个指针。试着用一个值代替。
QPixmap mypix (":/karim/test.png");
ui->label->setPixmap(mypix);
#1
11
The signature of the method you are trying to use is
您要使用的方法的签名是。
setPixmap ( const QPixmap & )
setPixmap (const QPixmap &)
but you are passing in a pointer. Try using a value instead.
但是你在传递一个指针。试着用一个值代替。
QPixmap mypix (":/karim/test.png");
ui->label->setPixmap(mypix);