You can ask QLabel to scale the image, by setting QLabel::scaledContents property to true. Other solution is to add scrollbars using QScrollArea.
When it comes to sizes, size() returns valid data only after you show the widget for the first time.
You can ask QLabel to scale the image, by setting QLabel::scaledContents property to true. Other solution is to add scrollbars using QScrollArea.
When it comes to sizes, size() returns valid data only after you show the widget for the first time.
hm... but that resizes them by stretching... that might look ugly when viewing photos, where the proportions are important. I thought about QImage::scaled(), but for that i need the actual size and (thats important) get noticed if the window gets resized (this resizes a QVBoxLayout in one case, where the label uses the most place it gets per default).
I added aimmediatly after setting the pixmap. the result is always the same: QSize(100, 30).Qt Code:
qDebug() << label0->size();To copy to clipboard, switch view to plain text mode
I already searched for a signal that gets emited when when resizing, but found none... The resizing of the images itself should not be the problem, as mentioned above, using QImage.
Or is there a better way? painting many pixmaps into one QLabel in a short period of time is rather slow.
Cant u get the size from size() as Jacek said ??
also QLabel is inherited from QWidget, so geometry() will also be available.
I got a new hdd, so i can't continue developing. Would it be possible to get the size if i add a QWidget into the QVBoxLayout and add the label to it? or any other constellation?
Yes, but you have to show that widget or at least wait for it to be polished, before you will get a valid size.
nope, i tried several things to get the size, using widgets, labels etc. every time i want to have the size i get a QSize(100,30) (or the equivalent using geometry()) so i have no chance to resize the images using QImage![]()
I hope this code help you.
Qt Code:
lab->setPixmap(p1); lab->show(); lab->setFixedHeight(p1.height()); lab->setFixedWidth(p1.width());To copy to clipboard, switch view to plain text mode
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
you can also use in spite of above.Qt Code:
lab->setFixedHeight(p1.height()); lab->setFixedWidth(p1.width());To copy to clipboard, switch view to plain text mode
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
thanks
now i understand where i was wrong. your code is much easier than my resize-function. Now the main problem to solve: how to get the maximum size the label can occupy?
I attached two screenshots. The first shows the splash, i changed the window-size to be a bit more than the fixed size of the label. Here, you can see the following structure:
where the label at the end holds the image that you can see. this should always use the maximum size, like your code does. I thought i could get the size by using a QWidget instead of the label and attach the label to the widgets layout (i used QVBoxLayout).Qt Code:
To copy to clipboard, switch view to plain text mode
The next screenshot shows the same problem. The area with a black border is a QLabel, that should also display images, but now with Qt::KeepAspectRatio. The Label should resize when window resizes, but by keeping the proportions of the file (image.size=label.size). Would be quite easy i thought some weeks ago...
Use maximumSize() and setMaximumSize() for this.Qt Code:
how to get the maximum size the label can occupyTo copy to clipboard, switch view to plain text mode
And use this code for your problem;
Qt Code:To copy to clipboard, switch view to plain text mode
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
You can set and use after the maximumSize of a widget using maximumSize() and setMaximumSize().
Anurag Shukla
A man who never makes mistake is the man who never does anything! Theodre Rosvelt!
Bookmarks