The Widget we should use to show pictures is a QLabel. we can do it directly from QtCreator, by setting its pixmap property.
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.
we can set the image of the QLabel using Qt Creator...
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 ?
The signature of the method you are trying to use is
setPixmap ( const QPixmap & )
but you are passing in a pointer. Try using a value instead.
QPixmap mypix (":/karim/test.png");
ui->label->setPixmap(mypix);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With