Hello all,
I m using Qt 4.3.4
My program has one QLabel in which I m dispalying an image using QPixmap.
I want to load another image in QPixmap at runtime..
How to do that???
Hello all,
I m using Qt 4.3.4
My program has one QLabel in which I m dispalying an image using QPixmap.
I want to load another image in QPixmap at runtime..
How to do that???
In the QPixmap or in the QLabel?
?Qt Code:
// or mypixmap->load("newFile"); mylabel->setPixmap(mypixmap);To copy to clipboard, switch view to plain text mode
QPixmap PixEllipseNose;
PixEllipseNose.load(QString::fromUtf8("images/Ellipse1.PNG"));
ui.lblNoseEllipse->setPixmap(PixEllipseNose);
Later some time in program (after timer goes off )I need to display another image
I want to load another image in existing PixEllipseNose but I dont want to set another pixmap in Qlabel .
How to do it???
You must create the QPixmap on the heap to do so. "QPixmap PixEllipseNose;" is deleted after the scope. UseQt Code:
To copy to clipboard, switch view to plain text mode
Hey but I declared "QPixmap PixEllipseNose;" as public variable in my class .
I m loading image in it in Class constructor.
Also the function in which I want to load another image in " PixEllipseNose" is a member function declared in "public" section.
//Class constructor
GLT_Submenu::GLT_Submenu(QWidget * parent):QDialog(parent)
{
ui.setupUi(this);
PixEllipseNose.load(QString::fromUtf8("images/Ellipse1.PNG"));
ui.lblNoseEllipse->setPixmap(PixEllipseNose);
}
void GLT_Submenu::f_FillNoseEllipse(int m_Stage)
{
QPen GreenPen(Qt::green, 1);
QPainter p(&PixEllipseNose);
p.setPen(GreenPen);
p.drawLine(EllipseNoseX1,EllipseNoseY1,EllipseNose X2,EllipseNoseY2);
ui.lblNoseEllipse->setPixmap(PixEllipseNose);
if(m_Stage ==LOAD_YELLOW_PEN)
{
//add Code to display next image in PixEllipseNose
}
}
Yeah, forget about the heap thing.Hey but I declared "QPixmap PixEllipseNose;" as public variable in my class .
And where is now your problem. Sorry can't get the point. Just use load() or set it to an QPainter to use it again. Everywhere you want.
EDIT: If you want to use it with a painter you may want to clear the pixmap first.
Hey I tried using
but the image is not changed ,still displayes the old image...PixEllipseNose.load(QString::fromUtf8("Images/YellowEllipse.PNG"));
Now what to do?
You have to set it on your label once again, because QLabel::setPixmap() copies your pixmap. So PixEllipseNose isn't a pointer to QLabel::pixmap().
I m using code
PixEllipseNose.load(QString::fromUtf8("Images/YellowEllipse.PNG"));
ui.lblNoseEllipse->setPixmap(PixEllipseNose);
But it doesnt change image.
if I use
it displayes the next image.ui.lblNoseEllipse->setPixmap(QPixmap(QString::fromUtf8("Images/YellowEllipse.PNG")));
But I want to change contents of "PixEllipseNose" instead off making QLabel to point to another pixmap.....
The contents of the pixmap will be changed,,, but how do you plan to see that the contents have been changed ? you need to paint it somewhere...dont u ?But I want to change contents of "PixEllipseNose" instead off making QLabel to point to another pixmap.....
and using QLabel::setPixmap is one of the easiest way, without making your own classes, and doing the painting yourself.
Last edited by aamer4yu; 28th March 2009 at 09:26.
Qt Code:
{ if (!d->pixmap || d->pixmap->cacheKey() != pixmap.cacheKey()) { d->clearContents(); } if (d->pixmap->depth() == 1 && !d->pixmap->mask()) d->updateLabel(); }To copy to clipboard, switch view to plain text mode
So your try to avoid increase memory are obsolete.
EDIT: Why your first option is not working has to do with the cacheKey. But that I also don't understand right.
Hey the thing is
I m painting this QPixmap image (Drawing some lines over the image using QPainter)
Now after some period of time I need the original image in QPixmap and start my drawing again.
I just want to change image of my Qpixmap at runtime .
How to aceive this??
Hey I got the solution to above problem
QPixmap PixEllipseNoseGreen,PixEllipseNoseGreenBKP;
PixEllipseNoseGreen.load(QString::fromUtf8("images/GreenEllipse.PNG"));
PixEllipseNoseGreenBKP.load(QString::fromUtf8("ima ges/GreenEllipse.PNG"));
After I finished painting QPixmap,I load the backup image as followes
PixEllipseNoseGreen.operator=(PixEllipseNoseGreenB KP);
Bookmarks