Results 1 to 4 of 4

Thread: How to resize QDialog when one of the widgets got (in)visible?

  1. #1
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    3
    Thanked 1 Time in 1 Post

    Question How to resize QDialog when one of the widgets got (in)visible?

    Hi!

    I have an object of QDialog. The dialog contains some widgets. Also there is an additional widget on the dialog (showing more details) that is visible/invisible with respect to the button "Show/hide more details" click. The widget locates in the bottom of the dialog. I want my dialog to resize itself when the widget "More details" have changed its visibility. I mean when I want to see more details my dialog gets longer (and vice-versa) but all widgets that are upper than the widget "More details" do not move at all. Now I use this code:
    Qt Code:
    1. // This is a slot for the button "Show/hide more details"
    2. void MyDialog::onMoreDetails(void)
    3. {
    4. bool visible = ui.widgetMoreInfo->isVisible();
    5. QSize dialogSize = this->size();
    6. int dialogHeight = dialogSize.height(),
    7. widgetHeight = ui.widgetMoreInfo->height();
    8.  
    9. ui.widgetMoreInfo->setVisible(!visible);
    10.  
    11. if (visible)
    12. dialogSize.setHeight(dialogHeight - widgetHeight - 6);
    13. else
    14. dialogSize.setHeight(dialogHeight + widgetHeight + 6);
    15.  
    16. this->resize(dialogSize);
    17. }
    To copy to clipboard, switch view to plain text mode 

    But it is not a universal method. Sometimes the dialog is resized okay but if one shrinks the dialog and clicks the button "More details" all upper widgets move. Maybe I should use layouts to resize?
    P.S.: the number 6 is a kind of margin or padding.

  2. #2
    Join Date
    Jul 2012
    Location
    Austria
    Posts
    15
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: How to resize QDialog when one of the widgets got (in)visible?

    Hy tehman,

    i think you are searching for a "resize to content" function. Sometimes ago i found a possible solution about your problem but i never test it myself.
    Take a look at the first answer ("It seems that calling....") of this thread - i think it could be a possible solution for your problem.

    Greetings
    Michael

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

    tehman (30th July 2012)

  4. #3
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: How to resize QDialog when one of the widgets got (in)visible?

    You might get some ideas from the Extension Example

  5. The following user says thank you to ChrisW67 for this useful post:

    tehman (30th July 2012)

  6. #4
    Join Date
    Jan 2012
    Posts
    15
    Thanks
    3
    Thanked 1 Time in 1 Post

    Default Re: How to resize QDialog when one of the widgets got (in)visible?

    Thank you guys, Michael and Chris! I will try to use your advises.

Similar Threads

  1. resize() in QDialog
    By santosh.kumar in forum Qt Programming
    Replies: 1
    Last Post: 17th August 2011, 15:38
  2. 'resize/maximize' button not visible
    By sindhumol_s in forum Qt Programming
    Replies: 2
    Last Post: 31st July 2009, 02:15
  3. QDialog Resize
    By navi1084 in forum Qt Programming
    Replies: 3
    Last Post: 22nd October 2008, 15:41
  4. QDialog resize
    By rajeshs in forum Qt Programming
    Replies: 18
    Last Post: 18th March 2008, 11:50
  5. QDialog resize ?
    By allensr in forum Qt Programming
    Replies: 6
    Last Post: 28th October 2007, 22:41

Tags for this Thread

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.