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?
Bookmarks