Results 1 to 6 of 6

Thread: Dynamically changing QGroupBox size

  1. #1
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs down Dynamically changing QGroupBox size

    In one of my windows I've placed QVBoxLayout with three QGroupBox inside. Each of QGroupBox posses his own QVBoxLayout in which resides custom widgets. QGroupBox are set without MaximumSize.
    Now - if I click on custom widgets - the should show extra QLabel below. But those lines are ... painted vertically squeezed.
    It looks like they are trying to be painted in place previously used only by one line. Hmm - maybe they need QSizePolicy? So for every QGroupBox I've set verticalPolicy to Expanding (so they should be shrinking and expanding when need).
    Almost no change. Now when I click - for a second space is prepared - but then everything is collapsing to state before.

    If I understand correctly - I need to say to QGroupBox in which one of item should expand to increase his size. This QGroupBox should say to Layout in which he resides - I need more space. But don't know how? I never use setMaximumHeight - only twice setMinimumHeight (for max height of QLabel). In one QGroupBox there are 8 items, in second - 4 and in last one only ONE. So place is enough to expand.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically changing QGroupBox size

    How do you show the label? Is it part of the custom widget or do you add it to the layout of the group box? Do your custom widgets have layouts or define sizeHints?

  3. #3
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically changing QGroupBox size

    Dialog is in one Layout. In this layout are 3 QGroupBox. Each groupbox have set internal Layout. In this layout resides custom widgets. This custom widgets are build with another internal Layout with two labels inside. One is always visible, other - only when user clicked in widget (by show/hide methods). Both labels have setMinimumHeight set to 25.

    The only way I see is to do this by changing sizeHint or StretchFactor in SizePolicy each time user clicked.
    Are there easier way?

    Other question is - how sizes are prepared? Is Layout on highest level (one for Dialog) asking his members - give me how much space you need. Those members asking their own, and so on. And only way to split space by parts ( half for first, third part for second, rest for second) is by using SizePolicy?
    If it's made that way - then only way I see here is by increasing vertical stretch factor every time when internal element are expanding and decrease - when they collapse.
    Last edited by T4ng10r; 30th March 2007 at 07:53.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically changing QGroupBox size

    Quote Originally Posted by T4ng10r View Post
    The only way I see is to do this by changing sizeHint or StretchFactor in SizePolicy each time user clicked.
    Are there easier way?
    If you have a layout then you don't need to change the size hint. Stretch factor is also not the way to go. First thing I'd try is to call invalidate() on the layout of the custom widget that changes.

    Other question is - how sizes are prepared? Is Layout on highest level (one for Dialog) asking his members - give me how much space you need. Those members asking their own, and so on. And only way to split space by parts ( half for first, third part for second, rest for second) is by using SizePolicy?
    In general the top level widget asks its layout to position its items according to the top level widget size. Then the layout asks each of its items for their sizeHint. Then the real size is calculated based on the size hint, minimum and maximum sizes and size policies. Then widgets are repositioned and asked to adjust their layouts.

  5. #5
    Join Date
    Feb 2007
    Location
    Wroclaw, Poland
    Posts
    72
    Thanks
    6
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Dynamically changing QGroupBox size

    Quote Originally Posted by wysota View Post
    In general the top level widget asks its layout to position its items according to the top level widget size. Then the layout asks each of its items for their sizeHint. Then the real size is calculated based on the size hint, minimum and maximum sizes and size policies. Then widgets are repositioned and asked to adjust their layouts.
    For me it sounds that once top level widget set size of their layout items - their sizes won't change. If children placed in layout requires more space to be drawn correctly - there's no way to change size 'auto-magically'.
    Once problem is only ONE LEVEL deep - it's ok.
    Look below.
    Qt Code:
    1. -------------DIALOG-----------------------------------
    2. | -------------groupBox1--------------------------- |
    3. | | item_1 | |
    4. | | item_2 | |
    5. | | - item_2_1 | |
    6. | | item_3 | |
    7. | | item_4 | |
    8. | ------------------------------------------------- |
    9. | -------------groupBox2--------------------------- |
    10. | | item_1 | |
    11. | | item_2 | |
    12. | | ... | |
    13. | ------------------------------------------------- |
    14. | -------------groupBox3--------------------------- |
    15. | | item_1 | |
    16. | ------------------------------------------------- |
    17. -----------------------------------------------------
    To copy to clipboard, switch view to plain text mode 

    Dialog Layout prepares space for all groupBoxes. If they are without sizeHint, minimum- , maximumSize and sizePolicies - size of all would be the same.
    Now - as long no item_x_1 is showed - no problem. It looks ok.
    When item_2_1 is show() - space for groupBox1 is not enough. groupBox1 inside layout tries to place all items as best as possible in given space. But its not enough.
    Perfectly would be if - when item_2_1->show() layout gets info - I need more space. Then he send this info to layout()->parent(), which reorganizes his layout to give more space to this child.

    In other place I used something like that - when user clicked inside groupBox - widget which was hidden is now showed. While processing click signal - I'm increasing this groupBox vertical stretch.
    It works, but - in my opinion - result aren't ... elegant.
    Modifying sizeHint, maximumSize and minimumSize when new child member is showed - with Layouts use - is nonsense and pointless.
    Here I should transfer signal to Dialog, change stretchFactor and redraw - not nice and flexible enough.
    Sounds -

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Dynamically changing QGroupBox size

    I think you are wrong. See the attached example. The size constraint is not required, it just adjusts the top level widget size.
    Attached Files Attached Files

Similar Threads

  1. Dynamically changing QFrame color
    By Doug Broadwell in forum Newbie
    Replies: 6
    Last Post: 16th October 2008, 09:22
  2. Dynamically changing QLabel background colour
    By T4ng10r in forum Qt Programming
    Replies: 19
    Last Post: 19th April 2007, 13:47
  3. changing the size of the tab width: QTabWidget
    By nikita in forum Qt Programming
    Replies: 2
    Last Post: 29th August 2006, 09:31
  4. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14
  5. Dynamically resizing in QT 3
    By kroenecker in forum Qt Programming
    Replies: 3
    Last Post: 9th January 2006, 19:37

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.