Hi this is the code i currently have:
Qt Code:
To copy to clipboard, switch view to plain text mode
where imagebox is a label.
How do i scale this to fit the label it is contained within?
Thanks for your time and trouble.
Hi this is the code i currently have:
Qt Code:
To copy to clipboard, switch view to plain text mode
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:
QPixmap scaledToHeight ( int height, Qt::TransformationMode mode = Qt::FastTransformation ) const
QPixmap scaledToWidth ( int width, Qt::TransformationMode mode = Qt::FastTransformation ) const
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
I think you are looking for:
JohQt Code:
ui->imagebox->setScaledContents(true);To copy to clipboard, switch view to plain text mode
Splatify (8th February 2011)
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).ui->imagebox->setScaledContents(true);
I've tried:
but it doesn't work.Qt Code:
{ pLabel->setAlignment( Qt::AlignHCenter | Qt::AlignVCenter ); qPixMap.scaledToWidth( 400 ); // width of the label pLabel->setPixmap( qPixMap ); }To copy to clipboard, switch view to plain text mode
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.Returns a scaled copy of the image.
So you need to do something like:
Qt Code:
qPixMap = qPixMap.scaledToWidth( 400 ); // width of the labelTo copy to clipboard, switch view to plain text mode
==========================signature=============== ==================
S.O.L.I.D principles (use them!):
https://en.wikipedia.org/wiki/SOLID_...iented_design)
Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.
ChrisOfBristol (8th April 2015)
Bookmarks