Qt Designer adds a geometry tag that contains the widget's default size in absolute units (pixels).
This is really annoying because if you edit a ui
file on a 4k monitor all of your ui
s will (by default) display with massive white space on a lower DPI system.
If I manually delete this tag, my windows have the expected size on first-show, but manually editing every ui
file each time I open them in Qt Designer feels wrong.
I'm using Qt 5.9.
What's the paradigmatic way to prevent Qt Designer from adding this XML tag?
In example.ui
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Example</class>
<widget class="QMainWindow" name="Example">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>970</width>
<height>1371</height>
</rect>
</property>
I am able to remove the geometry tags in Qt Designer like this:
This will automatically resize the form - but manually resizing it won't reinstate the geometry tag. However, if the form has a menu-bar, it will also add a geometry tag for that. So select menubar in the Object Inspector and then repeat steps 2 and 3 above. After doing that, I get this output:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralwidget"/>
<widget class="QMenuBar" name="menubar"/>
<widget class="QStatusBar" name="statusbar"/>
</widget>
<resources/>
<connections/>
</ui>
And after adding other widgets/menus/layouts and resizing the form, the geometry tags never reappear. This was all tested using Qt Designer 5.10.1 on Linux.