Results 1 to 3 of 3

Thread: Automatic Layout Computation for Preferences Dialog

  1. #1
    Join Date
    Oct 2017
    Posts
    18
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Automatic Layout Computation for Preferences Dialog

    Hi there,

    I want to implement a preferences dialog window that automagically resizes depending on the contents it shows. I want the dialog to behave the same way as the popup window that shows up when one executes the action

    "Tools" -> "Options"

    in the qtcreator IDE. My assumption is that this dialog consists mainly of

    - a QListView showing a list of option categories on the left and right besides it

    - a QStackedWidget which displays the options for the currently selected category in the option categories list.

    The preferences for a certain category are provided as QWidgets that are shown in the tabs of a QTabWidget.
    I noticed that the qtcreator's options dialog behaves very smart regarding its size: Initially the dialog window's size is as big that any of the available categories' tab pages can be shown inside the dialog without the need for a scroll bar (shown vertically or horizontally).
    If the dialog's size is reduced by the user then there is a minimum size that cannot be resized below.
    When afterwards the category is changed the dialog window automatically enlarges to provide enough space for display of the other category's options. Upon further category changes the size of the dialog is enlarged if necessary but never scaled down in case a preference tab needs less space than the dialog window currently occupies.
    I'd like to implement the same functionality for my preferences dialog but could not yet figure out how to accomplish that behavior.
    For the initial display of the dialog it must be somehow possible to iterate over all the categories and their associated preferences and calculate the required size for the display of each of them and finally set the dialog's size to the biggest required size encountered. Think, this initial calculation must take place in QDialog's overloaded slot method open().
    And for the calculation of the optimal size for display of a certain category's preference pages I have to compute that size and compare it with the current size of the dialog window and enlarge it if necessary.
    This should happen in a slot method that is connected with the currentChanged signal of the QStackedWidget instance.

    But how are all these computations to be implemented? I'm a bit confused of the many geometry-related properties in the QWidget class (which seems to be responsible for layout calculations).

    Could anyone enlighten me?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Automatic Layout Computation for Preferences Dialog

    Think, this initial calculation must take place in QDialog's overloaded slot method open().
    Better to put it in the QDialog::showEvent(). At this point, Qt has completely laid out the dialog and it is ready to be shown on screen. Prior to that point, layout is still occurring and you cannot be guaranteed that widgets contained within it have been properly sized and laid out.

    In the same way, I don't think you can correctly determine the sizes of pages in the stack widget that have not yet been shown until they actually execute their own showEvent(). Once this happens, you may be able to use the page's sizeHint() to determine the preferred size, and then resize your dialog accordingly.

    In most cases, if you use layouts properly in a QDialog and have not set a maximum size constraint, the dialog will expand itself automatically to hold its content. It usually will not shrink if it contains stacked pages that are smaller than the largest one shown so far.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Oct 2017
    Posts
    18
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Automatic Layout Computation for Preferences Dialog

    Thanks a lot! Using the showEvent() method for placing the code for the size calculation did the trick:

    setMinimumSize(sizeHint());

    made the dialog big enough that all the stacked widgets could be shown with proper size. Need to add that I created the different stacked widgets in qtdesigner and added them in qtdesigner to the QStackedWidget:

    Attachment 12959

Similar Threads

  1. Issue with Layout of Wizard Dialog
    By apatwork in forum Qt Programming
    Replies: 1
    Last Post: 3rd September 2018, 10:16
  2. Automatic reestructuring of elements of a grid layout
    By quimnuss in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2016, 11:14
  3. Qt Quick Components - layout of Dialog
    By finngruwier in forum Qt Quick
    Replies: 3
    Last Post: 13th September 2011, 15:28
  4. Resizeable Dialog/Layout (like Dolphin)
    By kiss-o-matic in forum Qt Programming
    Replies: 2
    Last Post: 20th December 2009, 23:18
  5. Resizing dialog with form layout
    By elizabeth.h1 in forum Qt Programming
    Replies: 2
    Last Post: 30th August 2009, 19:58

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.