QAbstractFormBuilder#
The QAbstractFormBuilder
class provides a default implementation for classes that create user interfaces at run-time. More…
Inherited by: QFormBuilder
Synopsis#
Functions#
def
applyPropertyInternally
(o, propertyName, value)def
errorString
()def
reset
()def
setWorkingDirectory
(directory)def
workingDirectory
()
Virtual functions#
def
addMenuAction
(action)def
checkProperty
(obj, prop)def
createAction
(parent, name)def
createActionGroup
(parent, name)def
createLayout
(layoutName, parent, name)def
createWidget
(widgetName, parentWidget, name)def
load
(dev[, parentWidget=None])def
save
(dev, widget)
Static functions#
def
toolBarAreaMetaEnum
()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description#
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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) super().__init__(parent) builder = QFormBuilder() file = QFile(":/forms/myWidget.ui") file.open(QFile.ReadOnly) myWidget = builder.load(file, self) file.close() layout = QVBoxLayout(self) layout.addWidget(myWidget)
To override certain aspects of the form builder’s behavior, subclass QAbstractFormBuilder
and reimplement the relevant virtual functions:
load()
handles reading of UI format files from arbitrary QIODevices, and construction of widgets from the XML data that they contain.
save()
handles saving of widget details in UI format to arbitrary QIODevices.
workingDirectory()
andsetWorkingDirectory()
control the directory in which forms are held. The form builder looks for other resources on paths relative to this directory.
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 module.
See also
Qt UI Tools
- class PySide6.QtDesigner.QAbstractFormBuilder#
Constructs a new form builder.
- PySide6.QtDesigner.QAbstractFormBuilder.addMenuAction(action)#
- Parameters:
action –
PySide6.QtGui.QAction
- PySide6.QtDesigner.QAbstractFormBuilder.applyPropertyInternally(o, propertyName, value)#
- Parameters:
propertyName – str
value – object
- Return type:
bool
- PySide6.QtDesigner.QAbstractFormBuilder.checkProperty(obj, prop)#
- Parameters:
obj –
PySide6.QtCore.QObject
prop – str
- Return type:
bool
- PySide6.QtDesigner.QAbstractFormBuilder.createAction(parent, name)#
- Parameters:
parent –
PySide6.QtCore.QObject
name – str
- Return type:
- PySide6.QtDesigner.QAbstractFormBuilder.createActionGroup(parent, name)#
- Parameters:
parent –
PySide6.QtCore.QObject
name – str
- Return type:
- PySide6.QtDesigner.QAbstractFormBuilder.createLayout(layoutName, parent, name)#
- Parameters:
layoutName – str
parent –
PySide6.QtCore.QObject
name – str
- Return type:
- PySide6.QtDesigner.QAbstractFormBuilder.createWidget(widgetName, parentWidget, name)#
- Parameters:
widgetName – str
parentWidget –
PySide6.QtWidgets.QWidget
name – str
- Return type:
- PySide6.QtDesigner.QAbstractFormBuilder.errorString()#
- Return type:
str
Returns a human-readable description of the last error occurred in load()
.
See also
- PySide6.QtDesigner.QAbstractFormBuilder.load(dev[, parentWidget=None])#
- Parameters:
dev –
PySide6.QtCore.QIODevice
parentWidget –
PySide6.QtWidgets.QWidget
- Return type:
Loads an XML representation of a widget from the given device
, and constructs a new widget with the specified parent
.
See also
- PySide6.QtDesigner.QAbstractFormBuilder.reset()#
- PySide6.QtDesigner.QAbstractFormBuilder.save(dev, widget)#
- Parameters:
dev –
PySide6.QtCore.QIODevice
widget –
PySide6.QtWidgets.QWidget
Saves an XML representation of the given widget
to the specified device
in the standard UI file format.
Note
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.
See also
- PySide6.QtDesigner.QAbstractFormBuilder.setWorkingDirectory(directory)#
- Parameters:
directory –
PySide6.QtCore.QDir
Sets the current working directory of the form builder to the specified directory
.
See also
- static PySide6.QtDesigner.QAbstractFormBuilder.toolBarAreaMetaEnum()#
- Return type:
- PySide6.QtDesigner.QAbstractFormBuilder.workingDirectory()#
- Return type:
Returns the current working directory of the form builder.
See also