Where is QLayout property leftMargin
-
Question
Where is QLayout property leftMargin in the code?
Situation
When I got the ui-file as described below.
The QFormLayout has clearly a leftMargin property.
But when I set this property from the code, like:Root->layout()->setProperty("leftMargin", 33);
This is not working.
There must be some magic at work here.Expected
I expected actually the QMargins typed property to behave like the QRect typed ones.
<property name="contentMargins"> <margins> <left>6</left> <top>6</top> <right>6</right> <bottom>6</bottom> </margins>
Has anyone an idea why this is?
Maybe an irreversible mistake made in an earlier version :(
The mentioned Ui-file
<?xml version="1.0" encoding="UTF-8"?> <ui version="4.0"> <class>Form</class> <widget class="QWidget" name="Root"> <property name="windowTitle"> <string>Form</string> </property> <property name="geometry"> <rect> <x>0</x> <y>0</y> <width>421</width> <height>100</height> </rect> </property> <layout class="QFormLayout" name="formLayout"> <property name="leftMargin"> <number>100</number> </property> <property name="topMargin"> <number>6</number> </property> <property name="rightMargin"> <number>6</number> </property> <property name="bottomMargin"> <number>6</number> </property> <item row="0" column="0"> <widget class="QLabel" name="label"> <property name="text"> <string>TextLabel</string> </property> <property name="buddy"> <cstring>lineEdit</cstring> </property> </widget> </item> <item row="0" column="1"> <widget class="QLineEdit" name="lineEdit"/> </item> </layout> </widget> </ui>
-
There is no such property documented in QFormLayout or QLayout, so it is unsurprising you cannot set it that way.
To set the individual (or all) margins use a combination of QLayout::contentsMargins() and QLayout::setContentsMargins().Here is an excerpt of what
uic
generates from your UI file:... if (Root->objectName().isEmpty()) Root->setObjectName(QString::fromUtf8("Root")); Root->resize(421, 100); formLayout = new QFormLayout(Root); formLayout->setObjectName(QString::fromUtf8("formLayout")); formLayout->setContentsMargins(100, 6, 6, 6); ...
Has anyone an idea why this is?
Maybe an irreversible mistake made in an earlier version :(No, not a mistake, a design choice. QRect and QLayout are different beasts. There is also no requirement for a one-to-one mapping between the UI file XML and properties.
-
@ChrisW67 said in Where is QLayout property leftMargin:
No, not a mistake, a design choice. QRect and QLayout are different beasts. There is also no requirement for a one-to-one mapping between the UI file XML and properties.
It seems just inconsequent having ui-file have properties on an QObject that does not exist in the code.
By the way, I'm not using the ui-file to be compiled but using QFormBuilder with some of work-arounds to load/create modify and save ui-files from the Concept Application I'm working on.
That is why I'm missing the properties on the layout object.