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.
Qt Code:
  1. setFrameStyle(QFrame::Panel | QFrame::Plain);
  2. setLineWidth(1);
To copy to clipboard, switch view to plain text mode 

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:
Qt Code:
  1. QSize Thumb::sizeHint() const
  2. {
  3. return QLabel::sizeHint() + QSize(20,20);
  4. }
To copy to clipboard, switch view to plain text mode 
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