Making QT believe a widget is bigger
Hi,
I have put a nuch of QLabels in a QGridLayout and given each a small QPixmap to get a collection of thumbnails.
Now I want to draw some decoration outside each pixmap/label. I can't simply reimplement paintEvent() of the QLabels and draw the extra stuff there because the drawing is clipped to a region with the exact size of the pixmap.
Well, QLabels are QFrames which can draw stuff outside, so my first approach was to put e.g.
in the constructor of Thumb (which inherits QLabel) to trick QT into believing it is about to draw a one-pixel frame around the QLabel.
paintEvent() now gets a bigger region, and I can draw my own decoration there.
This works fine, but the actual extra width/height is dependent on the current style and I'd like to avoid that dependence.
What is the proper way of telling QT that a widget need to be a little bigger? For testing purposes, I tried:
Code:
QSize Thumb
::sizeHint() const {
}
From debugging I can see that my reimplemented sizeHint is indeed called, and returns the expected value.
The rect() of the paintEvents are now slightly bigger (by a pixel or two, nowhere near the 20 I asked for).
It seems that the extra paintEvent-rect size only ate into the QGridLayout's spacing().
How do I get QGridLayout to understand that each Thumb is bigger, if reimplementing sizeHint doesn't help?
/Joakim Rosqvist
Re: Making QT believe a widget is bigger
Re: Making QT believe a widget is bigger
Yup, that worked!
There is a QLabel::setMargin() that also seems to do the trick. That margin is apparently added to the contentsMargins. Redundant functionality?