The QAbstractFormBuilder class provides a default implementation for classes that create user interfaces at run-time. 更多...
头: | #include <QAbstractFormBuilder> |
CMake: |
find_package(Qt6 REQUIRED COMPONENTS Designer)
target_link_libraries(mytarget PRIVATE Qt6::Designer) |
qmake: | QT += designer |
继承者: |
QAbstractFormBuilder () | |
virtual | ~QAbstractFormBuilder () |
QString | errorString () const |
virtual QWidget * | load (QIODevice * device , QWidget * parent = nullptr) |
virtual void | save (QIODevice * device , QWidget * widget ) |
void | setWorkingDirectory (const QDir & directory ) |
QDir | workingDirectory () const |
QAbstractFormBuilder provides a standard interface and a default implementation for constructing forms from user interface files. It is not intended to be instantiated directly. Use the QFormBuilder class to create user interfaces from UI files at run-time. For example:
MyForm::MyForm(QWidget *parent) : QWidget(parent) { QFormBuilder builder; QFile file(":/forms/myWidget.ui"); file.open(QFile::ReadOnly); QWidget *myWidget = builder.load(&file, this); file.close(); auto *layout = new QVBoxLayout(this); layout->addWidget(myWidget); }
To override certain aspects of the form builder's behavior, subclass QAbstractFormBuilder and reimplement the relevant virtual functions:
The QFormBuilder class is typically used by custom components and applications that embed Qt Designer . Standalone applications that need to dynamically generate user interfaces at run-time use the QUiLoader , found in the Qt UI Tools 模块。
另请参阅 Qt UI Tools .
Constructs a new form builder.
[virtual noexcept]
QAbstractFormBuilder::
~QAbstractFormBuilder
()
Destroys the form builder.
Returns a human-readable description of the last error occurred in load ().
另请参阅 load ().
[虚拟]
QWidget
*QAbstractFormBuilder::
load
(
QIODevice
*
device
,
QWidget
*
parent
= nullptr)
Loads an XML representation of a widget from the given device , and constructs a new widget with the specified parent .
另请参阅 save () 和 errorString ().
[虚拟]
void
QAbstractFormBuilder::
save
(
QIODevice
*
device
,
QWidget
*
widget
)
Saves an XML representation of the given widget 到指定 device in the standard UI file format.
注意: Unlike when saving a form in Qt Designer , all property values are written. This is because, the state of whether a property value was modified or not isn't stored in the Qt property system. The widget that is being saved, could have been created dynamically, not loaded via load (), so in this case the form builder isn't aware of the list of changed properties. Also, there's no generic way to do this for widgets that were created dynamically.
Therefore, you should remove properties that are not required from your resulting XML files, before loading them. Alternatively, if you already know which properties you want to save when you call this method, you can overload
computeProperties()
and return a filtered list of required properties. Otherwise, unexpected behavior may occur as some of these properties may depend on each other.
另请参阅 load ().
Sets the current working directory of the form builder to the specified directory .
另请参阅 workingDirectory ().
Returns the current working directory of the form builder.
另请参阅 setWorkingDirectory ().