Results 1 to 4 of 4

Thread: Inconsistent behaviour of QVBoxLayout

  1. #1
    Join Date
    Nov 2008
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Inconsistent behaviour of QVBoxLayout

    Hi there. I have a QWidget which contains a QScrollArea which contains a MyList which has a QVBoxLayout. MyList has a slot
    Qt Code:
    1. void MyList :: add_new () {
    2. MyWidget * w = new MyWidget (this);
    3. layout () -> addWidget (w);
    4. }
    To copy to clipboard, switch view to plain text mode 

    I can call add_new repeatedly from the MyList constructor and the behaviour is as expected: a new widget is added to the end of the list and eventually a scroll bar appears as the MyList widget grows.

    If I call add_new later as the result of a user action, the height of the MyList widget is fixed and everything is squashed to accomadate the new MyWidget.

    Is this a bug or do I need to change some setting?
    Last edited by spraff; 26th November 2008 at 17:02.

  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: Inconsistent behaviour of QVBoxLayout

    If I understand you correctly then yes, this is expected. Your top level widget gets some dimensions while it is being shown and then if you add more widgets, it is not resized anymore - the layout applied to it manages its current space. As the space doesn't change and the requirements for it grow, each widget gets less space. If you want to override this behaviour, apply a constraint to the top level widget's layout (Fixed probably being the one you want).

  3. #3
    Join Date
    Nov 2008
    Posts
    38
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Inconsistent behaviour of QVBoxLayout

    Can you please explain how a "Fixed" layout is supposed to allow growth? I don't understand the inner logic.

    (I'm having minor issues elsewhere in my app where widgets ought to push out their parents, so knowing what the mechanism is would help.)

    I wonder if this is somehow connected to the fact that sizePolicy sever seems to do anything

  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: Inconsistent behaviour of QVBoxLayout

    It says the dialog is always to be of the size equal to the sizeHint of its layout's widgets. If you add a new widget, the "total sizeHint" will grow, hence the dialog will grow with it. Note that I'm not talking about the "sizePolicy" of the dialog but of the size constraint of its layout.

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.