The best way to make a dialog (with e.g only labels and buttons) fixed size is
However in a multi screen environment moving such a dialog from one screen to another (slowly) in high DPI mode may cause a lot of flickering and the dialog may end up with controls placed completely wrong.
Steps to reproduce (at least the flickering part)
- Have two screens with very diffent device pixel ratio (2.0 vs 1.0). In my example I have two 4k screens with one set to 175 and the other to 125. (Monitor 1 (scale 125) is set to be on the right side)
- Compile attached example
- OR modify the example: examples\widgets\mainwindows\mainwindow )
int main(int argc, char **argv) (main.cpp)
as the first line of the function (before QApplication ctor) insert
and before mainWin.show() add
- Finally slowly move the dialog from one screen to the other. (On faster moves the risk of any flicking (and dialog mess) is reduced)
When the dialog moves to a new screen (in high DPI mode) Qt tries to change the window size in QGuiApplicationPrivate::processGeometryChangeEvent. However the size constraint will ensure that the dialog quickly afterwards will resize again. This new (layout constaint) size often causes the to end up being mainly on the previous Screen, so the dialog is nearly instantly moved backed to the screen it came from. Here it is again resized (twice). This will again cause the dialog end up on the screen Qt originally tried to change to.
Only a top left point check (which seems to be held on most or all resizes) prevents infinite screen changes, but a new small mouse movement will instantly repeat this resize the circus.
Somehow all these size changes can cause the controls to be completely wrong. (Though other examples may reproduce better than this mainwindow example)
This issue can be reproduced on Windows and may exist on Linux (not tested). It does not happen on Mac.