Results 1 to 9 of 9

Thread: layout update problem

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default layout update problem

    I have the following layout:

    Qt Code:
    1. <vl>
    2. <hl>
    3. <otherstuff/>
    4. </hl>
    5. <hl2>
    6. <tabwidget/>
    7. </hl2>
    8. <vl>
    To copy to clipboard, switch view to plain text mode 

    "Other stuff" includes a toggle button. If this button is toggled, i'd like to hide <tabwidget> or the entire <hl2> layout.
    I cant seem to find a way to hide an entire layout, so i called setVisible() on the tabwidget:



    Qt Code:
    1. ui.tabWidget->setVisible(ui.btnTog->isChecked());
    2. this->updateGeometry();
    3. this->update();
    4. ui.horizontalLayout_5->update();
    To copy to clipboard, switch view to plain text mode 

    As you can see i called all update/refresh related methods afterwards, but the dialog layout doesnt change.
    That means there's a big, empty unused spot where the tabwidget used to be.


    What do i have to do to force the widget to recalculate its layout and consider the now hidden tabwidget?

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

    Default Re: layout update problem

    Either your layouts are incorrect or you need to adjust size policies of other widgets to fill the space left by the tab widget (or both).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout update problem

    The other widgets are comboboxes and buttons, and hence dont grow vertically. Instead, i'd like the entire dialog to shrink to the size of said widgets.
    i have no clue what else i could change, here a screenshot + a small sample project.
    I'd be grateful if anyone could take a quick look!

    layoutProblem.ziplayoutproblem.jpg

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

    Default Re: layout update problem

    QLayout::setSizeConstraint() with QLayout::SetFixedSize
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout update problem

    thanks, that's better. But now the user cant re-size the dialog (which is desirable when the tabwidget is shown).
    I'll experiment some more with this, thanks again!

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

    Default Re: layout update problem

    Quote Originally Posted by tuli View Post
    thanks, that's better. But now the user cant re-size the dialog (which is desirable when the tabwidget is shown).
    I can't think of a sane behaviour of a widget that both lets the user resize it and forces a specific size to be set. If you really want, you can just call resize(sizeHint()) but it doesn't make it any saner. If the user resizes the dialog and then you force your own size then the user might not like it.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout update problem

    It makes sense when the widget height is only changable by the user if the tableWidget is present. if it is not, the height is fixed and only the width is of interest to the user.

    resize(sizeHint()) doesnt work, same for resize(minimumSize()). Both somehow give me a big empty spot where the tabwidget used to be.
    interestingly, i obtained mixed result when calling resize(height(), 0).
    if this i called from within the hide-button clicked() slot, it has no effect.

    if, however, i call it from the clicked() slot of another button, it works perfectly!


    Qt Code:
    1. void myform::bttong2clicked()
    2. {
    3. resize(width(), 0);
    4. }
    5.  
    6.  
    7. void myform::hidebuttonclicked()
    8. {
    9. ui.tabwidget ->setVisible(ui.hidebutton->isChecked());
    10. if(!ui.hidebutton->isVisible()
    11. resize(width(), 0);
    12. return;
    13. }
    To copy to clipboard, switch view to plain text mode 



    1) click hidebutton -> tabwidget disappears, empty space appears
    2) click button2 -> empty space disappears, window has been resized correctly. Width is maintained.
    3) click hidebutton -> tabwidget is shown again, window is resized apropriately


    The problem is that i have to click two button to make it disappear. Any idea why it doesnt work when i call it from within hidebuttonclicked()?

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

    Default Re: layout update problem

    Quote Originally Posted by tuli View Post
    It makes sense when the widget height is only changable by the user if the tableWidget is present.
    If that's what you want then you can lift the size constraint on the layout when the table widget is visible and set it back otherwise.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jul 2012
    Posts
    248
    Thanks
    29
    Thanked 15 Times in 14 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: layout update problem

    yeah, but then the user cannot change the width of the widget when the tabwidget is hidden. The width is always changable, the height only when the tabwidget is visible.

    Any ideas as to why my code above only works when called froma different slot? Because it does precisely what i want...

Similar Threads

  1. Replies: 8
    Last Post: 5th May 2021, 16:41
  2. update problem
    By rimie23 in forum Qt Programming
    Replies: 3
    Last Post: 13th May 2012, 21:54
  3. Form update problem
    By thefatladysingsopera in forum Newbie
    Replies: 9
    Last Post: 13th September 2011, 08:56
  4. Replies: 6
    Last Post: 13th August 2011, 18:31
  5. Problem with canvas()->update()
    By jblovloss in forum Qwt
    Replies: 1
    Last Post: 25th August 2009, 14:28

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
  •  
Qt is a trademark of The Qt Company.