Results 1 to 3 of 3

Thread: Making QT believe a widget is bigger

  1. #1
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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.
    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Making QT believe a widget is bigger

    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    drhex (23rd September 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default 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?

Similar Threads

  1. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 06:57
  2. minimize child widget
    By sreedhar in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2006, 12:02
  3. Replies: 4
    Last Post: 24th March 2006, 22:50
  4. How to reload widget plugins?
    By victorng in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2006, 23:27
  5. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 14:16

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.