PDA

View Full Version : Issue with Layout of Wizard Dialog



apatwork
29th August 2018, 18:40
Hi there,

I am developing a Qt app for the display of plots on Linux (RHEL7) and with Qt 5.9. I'm facing layout problems with a wizard dialog I implemented. The core issue is that when the contents of the wizard dialog change in some cases the size of the dialog window itself would have to change too, e.g. because the new wizard page's contents need more horizontal or vertical space. But this does not always happen.

I use the wizard dialog in two different contexts:

1. For the creation of a new plot. Here the first wizard page allows for specification of the plot's type, the second then asks for the to be created plot's properties like the dimensions of x and y axis and others. The second page requires significant more vertical space than the first page. Upon click on the wizard's "Next" button the wizard's vertical size grows as much as needed to make the second page fit into the available space which is fine!

2. I reuse the wizard for editing of an already existing plot's properties. In this scenario the first page which is shown in the wizard dialog is the one which is shown as second page in the plot creation scenario. To my big surprise the wizard dialog's size is not adjusted to the size required by that page when it is used as
first page. Instead parts of the contents are vertically squeezed (see screenshot).

12958

Interestingly when clicking with the left mouse button on a widget in the sqeezed wizard window this results in an immediate resize of the dialog to the proper size. The same happens when I move the cursor (and thus the focus) away from the wizard dialog.

I could not yet figure out what I can do to enforce the layout calculation programmatically that would lead to a larger size of the wizard dialog in the second usage scenario.
Any helpful hint would be highly appreciated.

apatwork
3rd September 2018, 11:59
Hi there,

thanks to a post of user d_stranz on another posting from me (https://www.qtcentre.org/threads/69744-Automatic-Layout-Computation-for-Preferences-Dialog) I found a solution for the problem described above too. Just like with my preferences dialog I implemented the slot method showEvent() for my sub-class of QWizard and now the wizard page shows up in proper size with no contents "squeezed" anymore.
But unfortunately this measure has a side effect. Now the wizard dialog gets placed in the upper left corner of the screen instead centered over the application's main window. I checked the position information calling the pos() method of QWidget in the body of the showEvent() method and it is really 0,0.
I wounder if there might be a way to avoid this wrong placement but if not, how could I compute the proper position (centered over the application's main window)? I assume that I could simply call move() with that position to fix the problem.

Found a code snippet that does the proper placement of my dialog centered over the application's main window:


QPoint dialogCenter = mapToGlobal(rect().center());
auto *parentWin(static_cast<QWidget*>(parent())->window());
QPoint parentWindowCenter(parentWin->mapToGlobal(parentWin->rect().center()));
move(parentWindowCenter - dialogCenter);

It is placed in the overridden showEvent() method in my QDialog sub-class to "repair" the wrong placement of my dialog which is the result of this code (placed in the showEvent() method too:


setMinimumSize(sizeHint());

So the only open question left over is: Why is that necessary at all?