Originally Posted by
anda_skoa
If the UI file has a property element for a widget then this should lead to a setProperty() call.
And this happens only if the property value is different from the default value for that property.
This is the ui file for an empty form:
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Form</class>
<widget class="QWidget" name="Form" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
</widget>
<pixmapfunction></pixmapfunction>
<connections/>
</ui>
<ui version="4.0" >
<author></author>
<comment></comment>
<exportmacro></exportmacro>
<class>Form</class>
<widget class="QWidget" name="Form" >
<property name="geometry" >
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle" >
<string>Form</string>
</property>
</widget>
<pixmapfunction></pixmapfunction>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
This is the generated Ui class:
/********************************************************************************
** Form generated from reading UI file 'form.ui'
**
** Created by: Qt User Interface Compiler version 5.1.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef FORM_H
#define FORM_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
{
if (Form->objectName().isEmpty())
Form->setObjectName(QStringLiteral("Form"));
Form->resize(400, 300);
retranslateUi(Form);
} // setupUi
{
Form
->setWindowTitle
(QApplication::translate("Form",
"Form",
0));
} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};
} // namespace Ui
QT_END_NAMESPACE
#endif // FORM_H
/********************************************************************************
** Form generated from reading UI file 'form.ui'
**
** Created by: Qt User Interface Compiler version 5.1.0
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/
#ifndef FORM_H
#define FORM_H
#include <QtCore/QVariant>
#include <QtWidgets/QAction>
#include <QtWidgets/QApplication>
#include <QtWidgets/QButtonGroup>
#include <QtWidgets/QHeaderView>
#include <QtWidgets/QWidget>
QT_BEGIN_NAMESPACE
class Ui_Form
{
public:
void setupUi(QWidget *Form)
{
if (Form->objectName().isEmpty())
Form->setObjectName(QStringLiteral("Form"));
Form->resize(400, 300);
retranslateUi(Form);
QMetaObject::connectSlotsByName(Form);
} // setupUi
void retranslateUi(QWidget *Form)
{
Form->setWindowTitle(QApplication::translate("Form", "Form", 0));
} // retranslateUi
};
namespace Ui {
class Form: public Ui_Form {};
} // namespace Ui
QT_END_NAMESPACE
#endif // FORM_H
To copy to clipboard, switch view to plain text mode
You can see the form (and the class) references only those properties that have non-default values. All others are silently ignored.
If you reset the "geometry" property to default in Designer, you get this (the "geometry" property is gone):
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Form</class>
<widget class="QWidget" name="Form">
<property name="windowTitle">
<string>Form</string>
</property>
</widget>
<resources/>
<connections/>
</ui>
To copy to clipboard, switch view to plain text mode
So the basic question is whether the UI file does refer to that property.
Edit: there is this code in QUiLoader (at least in the revision I have):
foreach (const DomProperty *p, properties) {
QUiTranslatableStringValue strVal;
const QString text
= convertTranslatable
(p, m_class,
&strVal
);
if (text.isEmpty())
continue;
const QByteArray name
= p
->attributeName
().
toUtf8();
if (dynamicTr) {
o
->setProperty
(dynname,
QVariant::fromValue(strVal
));
anyTrs = trEnabled;
}
o->setProperty(name, text);
}
foreach (const DomProperty *p, properties) {
QUiTranslatableStringValue strVal;
const QString text = convertTranslatable(p, m_class, &strVal);
if (text.isEmpty())
continue;
const QByteArray name = p->attributeName().toUtf8();
if (dynamicTr) {
const QByteArray dynname = QByteArray(PROP_GENERIC_PREFIX + name);
o->setProperty(dynname, QVariant::fromValue(strVal));
anyTrs = trEnabled;
}
o->setProperty(name, text);
}
To copy to clipboard, switch view to plain text mode
Which (lines #4-5) seems to imply that if a property has an empty string value in the ui file, it will be ignored. Note, this only applies to string properties.
Bookmarks