Hi this is the code i currently have:
where imagebox is a label.
How do i scale this to fit the label it is contained within?
Thanks for your time and trouble.
Printable View
Hi this is the code i currently have:
where imagebox is a label.
How do i scale this to fit the label it is contained within?
Thanks for your time and trouble.
Have a look at the QPixmap doc:
Quote:
QPixmap scaledToHeight ( int height, Qt::TransformationMode mode = Qt::FastTransformation ) const
QPixmap scaledToWidth ( int width, Qt::TransformationMode mode = Qt::FastTransformation ) const
I think you are looking for:
JohCode:
ui->imagebox->setScaledContents(true);
Thanks Joh, your solution worked great.
Hi,
is great, however I need to scale the content of the label background picture just to the width (I've got always wider, then higher pictures and I do not want to make images to be deformed).Quote:
ui->imagebox->setScaledContents(true);
I've tried:
but it doesn't work.Code:
{ pLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); qPixMap.scaledToWidth( 400 ); // width of the label pLabel->setPixmap( qPixMap ); }
Can anybody suggest me how to do that.
I'll be grateful for an explanation, why the code above doesn't work.
Thank you a lot.
you didn't explain what "doesn't work" mean.
But I can prity much guess.
The docs for this method says:
So it does not alter the object calling the method, but RETURNS the result.Quote:
Returns a scaled copy of the image.
So you need to do something like:
Code:
qPixMap = qPixMap.scaledToWidth( 400 ); // width of the label