Change the size of pixmap in a label
Re: Change the size of pixmap in a label
Re: Change the size of pixmap in a label
Re: Change the size of pixmap in a label
The Qt documentation is one of the best. I wonder why people don't read it.
Quote:
Returns a copy of the image scaled to a rectangle with the given width and height
Re: Change the size of pixmap in a label
you're right, thanks very much :D
Re: Change the size of pixmap in a label
Re: Change the size of pixmap in a label
What happens if you use:
Code:
imageLabel
->setPixmap
(QPixmap::fromImage(image.
scaled(200,
200)));
Re: Change the size of pixmap in a label
it's work but this or that "image = image.scaled(200,200,Qt::IgnoreAspectRatio,Qt::Fas tTransformation);" is the same. i tallking about the scaled function for pixmap.
Re: Change the size of pixmap in a label
it's work, but this is the same of "image = image.scaled(200,200,Qt::IgnoreAspectRatio,Qt::Fas tTransformation);".
Why i can't use the scaled function of pixmap.
Re: Change the size of pixmap in a label
Re: Change the size of pixmap in a label
i tried and the image doesn't resize! :S
Re: Change the size of pixmap in a label
Code:
#include "mainwindow.h"
#include <QtGui>
MainWindow::MainWindow(QWidget *parent) :
QWidget(parent)
{
QHBoxLayout *lay=new QHBoxLayout;
setLayout(lay);
QImage image("comando.jpg");
QLabel *imageLabel = new QLabel(this);
lay->addWidget(imageLabel);
imageLabel->setPixmap(QPixmap::fromImage(image.scaled(400,400,Qt::KeepAspectRatio,Qt::FastTransformation)));
qDebug() << imageLabel->pixmap()->size();
}
MainWindow::~MainWindow()
{
}
Now all the time i want change the imagelabel i will need to set again the pixmap :s I resize the image all the time that the user will change the mainwindow size.
Re: Change the size of pixmap in a label
metRo_: Yes, that is true, whether you resize the image and extract its pixmap each time, or save the extracted pixmap and resize the pixmap each time. If the label can change size and you want the pixmap to change size with it, somebody has to resize the pixmap. In Qt, that somebody is you.
One option is to subclass QLabel and override the resizeEvent() method. Within that, resize the pixmap (from the original! don't keep resizing the resized image!), and call setPixmap(). So you probably want a setOriginalPixmap() method also, in case you want to change the image that's on the the label.
Code:
void setOriginalPixmap
(QPixmap *pixmap
) {
if (original_pixmap)
delete original_pixmap;
original_pixmap = pixmap;
setScaledPixmap();
}
{
setScaledPixmap();
}
void setScaledPixmap (void)
{
scaled_pixmap = original_pixmap->scaled(width(), height(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
setPixmap(scaled_pixmap);
}
Re: Change the size of pixmap in a label
@dflo: Welcome!
But this thread is quite old to be picked up, don't you think?
Joh
Re: Change the size of pixmap in a label
Yeah probably. I was looking for something else, and meanwhile I found some questions I could answer. Maybe metRo_ put his project on hold and will come back to it? :)
Thanks for the welcome!
Re: Change the size of pixmap in a label
Yeah :-> Just don't be disappointed if nothing happens - that's all I wanted to say.
Happy coding,
Johannes
Re: Change the size of pixmap in a label
First set the pixmap to the label.
Then, set the size of the label by:-
Code:
label.setPixmap(pix);
label.setFixedSize(w,h);