QDesignerFormWindowInterface Class
QDesignerFormWindowInterface 类允许您查询和操作出现在Qt Widgets Designer 工作区中的表单窗口。更多内容...
| 标题: | #include <QDesignerFormWindowInterface> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Designer) target_link_libraries(mytarget PRIVATE Qt6::Designer) |
| qmake: | QT += designer |
| 继承自: | QWidget |
公共类型
| flags | Feature |
| enum | FeatureFlag { EditFeature, GridFeature, TabOrderFeature, DefaultFeature } |
| enum | ResourceFileSaveMode { SaveAllResourceFiles, SaveOnlyUsedResourceFiles, DontSaveResourceFiles } |
公共函数
| QDesignerFormWindowInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = {}) | |
| virtual | ~QDesignerFormWindowInterface() |
| virtual QDir | absoluteDir() const = 0 |
| QStringList | activeResourceFilePaths() const |
| virtual void | addResourceFile(const QString &path) = 0 |
| virtual QString | author() const = 0 |
| virtual QStringList | checkContents() const = 0 |
| virtual QString | comment() const = 0 |
| virtual QString | contents() const = 0 |
| virtual QDesignerFormEditorInterface * | core() const |
| virtual QDesignerFormWindowCursorInterface * | cursor() const = 0 |
| virtual void | emitSelectionChanged() = 0 |
| virtual QString | exportMacro() const = 0 |
| virtual QDesignerFormWindowInterface::Feature | features() const = 0 |
| virtual QString | fileName() const = 0 |
| virtual QWidget * | formContainer() const = 0 |
| virtual QPoint | grid() const = 0 |
| virtual bool | hasFeature(QDesignerFormWindowInterface::Feature feature) const = 0 |
| virtual QStringList | includeHints() const = 0 |
| virtual bool | isDirty() const = 0 |
| virtual bool | isManaged(QWidget *widget) const = 0 |
| virtual void | layoutDefault(int *margin, int *spacing) = 0 |
| virtual void | layoutFunction(QString *margin, QString *spacing) = 0 |
| virtual QString | pixmapFunction() const = 0 |
| virtual void | removeResourceFile(const QString &path) = 0 |
| virtual QDesignerFormWindowInterface::ResourceFileSaveMode | resourceFileSaveMode() const = 0 |
| virtual QStringList | resourceFiles() const = 0 |
| virtual void | setAuthor(const QString &author) = 0 |
| virtual void | setComment(const QString &comment) = 0 |
| virtual bool | setContents(QIODevice *device, QString *errorMessage = 0) = 0 |
| virtual void | setExportMacro(const QString &exportMacro) = 0 |
| virtual void | setIncludeHints(const QStringList &includeHints) = 0 |
| virtual void | setLayoutDefault(int margin, int spacing) = 0 |
| virtual void | setLayoutFunction(const QString &margin, const QString &spacing) = 0 |
| virtual void | setMainContainer(QWidget *mainContainer) = 0 |
| virtual void | setPixmapFunction(const QString &pixmapFunction) = 0 |
| virtual void | setResourceFileSaveMode(QDesignerFormWindowInterface::ResourceFileSaveMode behavior) = 0 |
公共槽
| void | activateResourceFilePaths(const QStringList &paths, int *errorCount = nullptr, QString *errorMessages = nullptr) |
| virtual void | clearSelection(bool update = true) = 0 |
| virtual void | manageWidget(QWidget *widget) = 0 |
| virtual void | selectWidget(QWidget *widget, bool select = true) = 0 |
| virtual bool | setContents(const QString &contents) = 0 |
| virtual void | setDirty(bool dirty) = 0 |
| virtual void | setFeatures(QDesignerFormWindowInterface::Feature features) = 0 |
| virtual void | setFileName(const QString &fileName) = 0 |
| virtual void | setGrid(const QPoint &grid) = 0 |
| virtual void | unmanageWidget(QWidget *widget) = 0 |
信号
| void | aboutToUnmanageWidget(QWidget *widget) |
| void | activated(QWidget *widget) |
| void | changed() |
| void | featureChanged(QDesignerFormWindowInterface::Feature feature) |
| void | fileNameChanged(const QString &fileName) |
| void | geometryChanged() |
| void | mainContainerChanged(QWidget *mainContainer) |
| void | objectRemoved(QObject *object) |
| void | resourceFilesChanged() |
| void | selectionChanged() |
| void | widgetManaged(QWidget *widget) |
| void | widgetRemoved(QWidget *widget) |
| void | widgetUnmanaged(QWidget *widget) |
静态公共成员
| QDesignerFormWindowInterface * | findFormWindow(QObject *object) |
| QDesignerFormWindowInterface * | findFormWindow(QWidget *widget) |
详细说明
QDesignerFormWindowInterface 提供有关关联表单窗口的信息,并允许修改其属性。该接口并非旨在直接实例化,而是用于访问由Qt Widgets Designer 的form window manager 控制的Qt Widgets Designer 的当前表单窗口。
如果您要查找包含特定小部件的表单窗口,可以使用静态函数QDesignerFormWindowInterface::findFormWindow():
auto *formWindow = QDesignerFormWindowInterface::findFormWindow(myWidget);此外,你还可以通过 `Qt Widgets Designer` 的表单窗口管理器访问任何当前表单窗口:使用 `QDesignerFormEditorInterface::formWindowManager()` 函数获取该管理器的接口。获得该接口后,即可通过 `QDesignerFormWindowManagerInterface::formWindow()` 函数访问 `Qt Widgets Designer` 的所有当前表单窗口。例如:
QList<QDesignerFormWindowInterface *> forms;
auto *manager = formEditor->formWindowManager();
for (int i = 0; i < manager->formWindowCount(); ++i)
forms.append(manager->formWindow(i));Qt Widgets Designer 当前QDesignerFormEditorInterface 对象(如上例中的formEditor )的指针由QDesignerCustomWidgetInterface::initialize() 函数的参数提供。在实现自定义控件插件时,您必须继承QDesignerCustomWidgetInterface 类,以便将您的插件暴露给Qt Widgets Designer 。
获得表单窗口后,即可查询其属性。例如,一个普通的自定义小部件插件仅在其顶级由Qt Widgets Designer 管理,也就是说,其任何子小部件都无法在Qt Widgets Designer 的工作区中调整大小。 但 QDesignerFormWindowInterface 提供了一些函数,使您可以控制小部件是否应由Qt Widgets Designer 管理:
if (formWindow->isManaged(myWidget))
formWindow->manageWidget(myWidget->childWidget);与小部件管理相关的函数完整列表如下:isManaged()、manageWidget() 和unmanageWidget()。此外还有几个相关的信号:widgetManaged()、widgetRemoved()、aboutToUnmanageWidget() 和widgetUnmanaged()。
除了控制控件的管理外,您还可以通过selectWidget()、clearSelection()和emitSelectionChanged()函数,以及selectionChanged()信号来控制表单窗口中的当前选中项。
您还可以使用absoluteDir() 获取表单的存储位置信息,使用includeHints() 获取其包含文件信息,并使用layoutDefault()、layoutFunction() 和pixmapFunction() 获取其布局和像素图函数信息。您可以使用isDirty() 函数来判断表单窗口是否已被修改(但未保存)。 您可以获取其author()、contents()、fileName()、关联的comment()和exportMacro()、mainContainer()、features()、grid()以及resourceFiles()。
该接口还提供了函数和槽(slots),允许您修改其中大部分信息。唯一例外的是存储表单窗口的目录。最后,还有几个信号与上述信息的变更以及表单窗口的整体变化相关。
另请参阅 QDesignerFormWindowCursorInterface 、QDesignerFormEditorInterface 以及QDesignerFormWindowManagerInterface 。
成员类型文档
enum QDesignerFormWindowInterface::FeatureFlag
flags QDesignerFormWindowInterface::Feature
此枚举描述了可用的、且可通过表单窗口界面进行控制的功能。在查询表单窗口以确定其支持哪些功能时,会使用这些值:
| 常量 | 值 | 描述 |
|---|---|---|
QDesignerFormWindowInterface::EditFeature | 0x01 | 表单编辑 |
QDesignerFormWindowInterface::GridFeature | 0x02 | 用于编辑的网格显示和对齐网格功能 |
QDesignerFormWindowInterface::TabOrderFeature | 0x04 | Tab 顺序管理 |
QDesignerFormWindowInterface::DefaultFeature | EditFeature | GridFeature | 对默认功能(表单编辑和网格)的支持 |
Feature 类型是QFlags<FeatureFlag> 的 typedef 定义。它存储 FeatureFlag 值的“或”组合。
另请参阅 hasFeature() 和features()。
enum QDesignerFormWindowInterface::ResourceFileSaveMode
此枚举描述了资源文件的保存方式。
| 常量 | 值 | 描述 |
|---|---|---|
QDesignerFormWindowInterface::SaveAllResourceFiles | 0 | 保存所有资源文件。 |
QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles | 1 | 保存窗体所用的资源文件。 |
QDesignerFormWindowInterface::DontSaveResourceFiles | 2 | 不保存资源文件。 |
成员函数文档
[explicit] QDesignerFormWindowInterface::QDesignerFormWindowInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = {})
根据给定的parent 和指定的窗口flags ,构建一个表单窗口界面。
[virtual noexcept] QDesignerFormWindowInterface::~QDesignerFormWindowInterface()
销毁表单窗口界面。
[signal] void QDesignerFormWindowInterface::aboutToUnmanageWidget(QWidget *widget)
每当表单上的某个控件即将变为非托管状态时,都会发出此信号。当发出此信号时,指定的widget 仍处于托管状态,随后会发出widgetUnmanaged()信号,以指示其何时不再处于托管状态。
另请参阅 unmanageWidget() 和isManaged()。
[pure virtual] QDir QDesignerFormWindowInterface::absoluteDir() const
返回包含表单窗口中显示的表单的目录的绝对路径。
[slot] void QDesignerFormWindowInterface::activateResourceFilePaths(const QStringList &paths, int *errorCount = nullptr, QString *errorMessages = nullptr)
激活资源(.qrc)文件路径paths ,并将错误数量返回至errorCount ,将错误消息返回至errorMessages 。Qt Widgets Designer 使用QResource 类加载资源,使其可供表单编辑使用。
在 IDE 集成中,可以激活项目资源(.qrc)文件的列表,使其可供Qt Widgets Designer 使用。
另请参阅 activeResourceFilePaths() 和QResource 。
[signal] void QDesignerFormWindowInterface::activated(QWidget *widget)
每当表单上的某个控件被激活时,都会触发此信号。被激活的控件由widget 指定。
QStringList QDesignerFormWindowInterface::activeResourceFilePaths() const
返回当前在Qt Widgets Designer 中加载的活跃资源(.qrc)文件路径。
另请参阅 activateResourceFilePaths()。
[pure virtual] void QDesignerFormWindowInterface::addResourceFile(const QString &path)
将位于指定path 的资源文件添加到表单所使用的资源中。
另请参阅 resourceFiles() 和resourceFilesChanged()。
[pure virtual] QString QDesignerFormWindowInterface::author() const
返回当前窗口中显示的表单的作者或创建者的详细信息。
另请参阅 setAuthor()。
[signal] void QDesignerFormWindowInterface::changed()
每当表单发生更改时,都会触发此信号。
[pure virtual] QStringList QDesignerFormWindowInterface::checkContents() const
对当前表单进行检查,并返回一个包含潜在问题(例如,在未排版的表单中出现顶级分隔符)的富文本警告列表。
IDE 集成可在处理保存操作之前调用此方法。
[pure virtual slot] void QDesignerFormWindowInterface::clearSelection(bool update = true)
清除表单窗口中的当前选中项。如果update 为真,则调用emitSelectionChanged()函数,并触发selectionChanged()信号。
另请参阅 selectWidget()。
[pure virtual] QString QDesignerFormWindowInterface::comment() const
返回关于当前在窗口中显示的表单的相关信息。
另请参阅 setComment()。
[pure virtual] QString QDesignerFormWindowInterface::contents() const
返回当前在窗口中显示的表单内容的详细信息。
另请参阅 setContents()。
[virtual] QDesignerFormEditorInterface *QDesignerFormWindowInterface::core() const
返回指向Qt Widgets Designer 当前QDesignerFormEditorInterface 对象的指针。
[pure virtual] QDesignerFormWindowCursorInterface *QDesignerFormWindowInterface::cursor() const
返回表单窗口所使用的光标接口。
[pure virtual] void QDesignerFormWindowInterface::emitSelectionChanged()
发出selectionChanged()信号。
另请参阅 selectWidget() 和clearSelection()。
[pure virtual] QString QDesignerFormWindowInterface::exportMacro() const
返回与当前窗口中显示的表单关联的导出宏。该导出宏用于在编译表单以生成小部件插件时。
另请参阅 setExportMacro() 以及《为Qt Widgets Designer 创建自定义小部件》。
[signal] void QDesignerFormWindowInterface::featureChanged(QDesignerFormWindowInterface::Feature feature)
每当表单中的某个字段发生变化时,都会触发此信号。新字段由feature 指定。
另请参阅 setFeatures()。
[pure virtual] QDesignerFormWindowInterface::Feature QDesignerFormWindowInterface::features() const
返回与该接口关联的表单窗口所提供的功能组合。可将返回的值与Feature 枚举值进行比对,以确定该窗口支持哪些功能。
另请参阅 setFeatures() 和hasFeature()。
[pure virtual] QString QDesignerFormWindowInterface::fileName() const
返回描述当前显示的表单的 UI 文件的文件名。
另请参阅 setFileName()。
[signal] void QDesignerFormWindowInterface::fileNameChanged(const QString &fileName)
每当表单的文件名发生变化时,都会触发此信号。新文件名由fileName 指定。
另请参阅 setFileName()。
[static] QDesignerFormWindowInterface *QDesignerFormWindowInterface::findFormWindow(QObject *object)
返回给定object 的表单窗口接口。
[static] QDesignerFormWindowInterface *QDesignerFormWindowInterface::findFormWindow(QWidget *widget)
返回给定widget 的表单窗口接口。
[pure virtual] QWidget *QDesignerFormWindowInterface::formContainer() const
返回包含主容器小部件的小部件的表单。
[signal] void QDesignerFormWindowInterface::geometryChanged()
每当表单的几何属性发生变化时,都会触发此信号。
[pure virtual] QPoint QDesignerFormWindowInterface::grid() const
返回表单窗口使用的网格间距。
另请参阅 setGrid()。
[pure virtual] bool QDesignerFormWindowInterface::hasFeature(QDesignerFormWindowInterface::Feature feature) const
如果表单窗口提供了指定的feature ,则返回true;否则返回false。
另请参阅 features()。
[pure virtual] QStringList QDesignerFormWindowInterface::includeHints() const
返回一个包含将要包含在表单窗口关联 UI 文件中的头文件列表。
头文件可以是本地文件(即相对于项目目录),"mywidget.h" ,也可以是全局文件(即属于 Qt 或编译器的标准库):<QtGui/QWidget> 。
另请参阅 setIncludeHints()。
[pure virtual] bool QDesignerFormWindowInterface::isDirty() const
如果表单窗口处于“未保存”状态(已修改但未保存),则返回 true;否则返回 false。
另请参阅 setDirty()。
[pure virtual] bool QDesignerFormWindowInterface::isManaged(QWidget *widget) const
如果指定的widget 由表单窗口管理,则返回true;否则返回false。
另请参阅 manageWidget()。
[pure virtual] void QDesignerFormWindowInterface::layoutDefault(int *margin, int *spacing)
在指定的margin 和spacing 变量中,为表单的默认布局填充默认边距和间距。
另请参阅 setLayoutDefault()。
[pure virtual] void QDesignerFormWindowInterface::layoutFunction(QString *margin, QString *spacing)
将表单布局的当前边距和间距填入指定的margin 和spacing 变量中。
另请参阅 setLayoutFunction()。
[signal] void QDesignerFormWindowInterface::mainContainerChanged(QWidget *mainContainer)
每当主容器发生变化时,都会触发此信号。新容器由mainContainer 指定。
另请参阅 setMainContainer()。
[pure virtual slot] void QDesignerFormWindowInterface::manageWidget(QWidget *widget)
指示表单窗口管理指定的widget 。
另请参阅 isManaged()、unmanageWidget() 和widgetManaged()。
[signal] void QDesignerFormWindowInterface::objectRemoved(QObject *object)
每当某个对象(例如一个操作或QButtonGroup )从表单中移除时,都会触发此信号。被移除的对象由object 指定。
[pure virtual] QString QDesignerFormWindowInterface::pixmapFunction() const
返回用于将位图加载到表单窗口中的函数名称。
另请参阅 setPixmapFunction()。
[pure virtual] void QDesignerFormWindowInterface::removeResourceFile(const QString &path)
从表单所使用的资源文件列表中移除位于指定路径path 的资源文件。
另请参阅 resourceFiles() 和resourceFilesChanged()。
[pure virtual] QDesignerFormWindowInterface::ResourceFileSaveMode QDesignerFormWindowInterface::resourceFileSaveMode() const
返回资源文件的保存模式行为。
另请参阅 setResourceFileSaveMode()。
[pure virtual] QStringList QDesignerFormWindowInterface::resourceFiles() const
返回一个列表,其中包含表单窗口当前正在使用的资源文件的路径。
另请参阅 addResourceFile() 和removeResourceFile()。
[signal] void QDesignerFormWindowInterface::resourceFilesChanged()
每当表单所使用的资源文件列表发生变化时,都会触发此信号。
另请参阅 resourceFiles()。
[pure virtual slot] void QDesignerFormWindowInterface::selectWidget(QWidget *widget, bool select = true)
如果select 为真,则选中给定的widget ;否则,widget 将被取消选中。
另请参阅 clearSelection() 和selectionChanged()。
[signal] void QDesignerFormWindowInterface::selectionChanged()
每当表单中的选中项发生变化时,都会触发此信号。
另请参阅 selectWidget() 和clearSelection()。
[pure virtual] void QDesignerFormWindowInterface::setAuthor(const QString &author)
将表单的作者或创建者的详细信息设置为指定的author 。
另请参阅 author()。
[pure virtual] void QDesignerFormWindowInterface::setComment(const QString &comment)
将表单的相关信息设置为指定的comment 。该信息应为关于该表单的人可读注释。
另请参阅 comment()。
[pure virtual slot] bool QDesignerFormWindowInterface::setContents(const QString &contents)
使用从指定的contents 字符串中读取的数据设置表单内容,并返回操作是否成功。
注意:此 插槽是重载的。要连接到此插槽:
// Connect using qOverload:
connect(sender, &SenderClass::signal,
designerFormWindowInterface, qOverload(&QDesignerFormWindowInterface::setContents));
// Or using a lambda as wrapper:
connect(sender, &SenderClass::signal,
designerFormWindowInterface, [receiver = designerFormWindowInterface](const QString &contents) { receiver->setContents(contents); }); 另请参阅 contents()。
[pure virtual] bool QDesignerFormWindowInterface::setContents(QIODevice *device, QString *errorMessage = 0)
使用从给定的device 中获取的数据设置表单内容,并返回加载是否成功。如果失败,则将错误消息保存在errorMessage 中。
数据可从QFile 对象或QIODevice 的任何其他子类中读取。
[pure virtual slot] void QDesignerFormWindowInterface::setDirty(bool dirty)
如果dirty 为真,则表单窗口被标记为“已修改”,这意味着该窗口已被修改但尚未保存。如果dirty 为假,则表单窗口被视为未被修改。
另请参阅 isDirty()。
[pure virtual] void QDesignerFormWindowInterface::setExportMacro(const QString &exportMacro)
将表单窗口的导出宏设置为exportMacro 。在构建小部件插件时,会使用该导出宏将表单的接口导出到其他组件。
另请参阅 exportMacro()。
[pure virtual slot] void QDesignerFormWindowInterface::setFeatures(QDesignerFormWindowInterface::Feature features)
为表单窗口启用指定的features 。
另请参阅 features() 和featureChanged()。
[pure virtual slot] void QDesignerFormWindowInterface::setFileName(const QString &fileName)
将表单的文件名设置为给定的fileName 。
另请参阅 fileName() 和fileNameChanged()。
[pure virtual slot] void QDesignerFormWindowInterface::setGrid(const QPoint &grid)
将表单窗口的网格大小设置为grid 中指定的点。在此函数中,QPoint 中的坐标用于指定网格中矩形的尺寸。
另请参阅 grid()。
[pure virtual] void QDesignerFormWindowInterface::setIncludeHints(const QStringList &includeHints)
将表单窗口相关联的 UI 文件中要包含的头文件设置为指定的includeHints 。
头文件可以是本地文件(即相对于项目目录),"mywidget.h" ,也可以是全局文件(即属于 Qt 或编译器的标准库):<QtGui/QWidget> 。
另请参阅 includeHints()。
[pure virtual] void QDesignerFormWindowInterface::setLayoutDefault(int margin, int spacing)
设置表单布局的默认margin 和spacing 。
另请参阅 layoutDefault()。
[pure virtual] void QDesignerFormWindowInterface::setLayoutFunction(const QString &margin, const QString &spacing)
设置表单布局的margin 和spacing 。
当uic 为表单生成代码时,默认的布局属性将被相应的布局函数所替换,前提是已指定这些函数。当不同环境需要为同一表单采用不同的布局时,此功能非常有用。
另请参阅 layoutFunction()。
[pure virtual] void QDesignerFormWindowInterface::setMainContainer(QWidget *mainContainer)
将表单上的主容器控件设置为指定的mainContainer 。
另请参阅 mainContainerChanged()。
[pure virtual] void QDesignerFormWindowInterface::setPixmapFunction(const QString &pixmapFunction)
将用于将位图加载到表单窗口中的函数设置为给定的pixmapFunction 。
另请参阅 pixmapFunction()。
[pure virtual] void QDesignerFormWindowInterface::setResourceFileSaveMode(QDesignerFormWindowInterface::ResourceFileSaveMode behavior)
设置资源文件的保存模式behavior 。
另请参阅 resourceFileSaveMode()。
[pure virtual slot] void QDesignerFormWindowInterface::unmanageWidget(QWidget *widget)
指示表单窗口不要管理指定的widget 。
另请参阅 aboutToUnmanageWidget() 和widgetUnmanaged()。
[signal] void QDesignerFormWindowInterface::widgetManaged(QWidget *widget)
每当表单上的某个控件成为受管控件时,都会触发此信号。新成为受管控件的控件由 `widget` 指定。
另请参阅 manageWidget()。
[signal] void QDesignerFormWindowInterface::widgetRemoved(QWidget *widget)
每当表单中移除一个控件时,都会触发此信号。被移除的控件由widget 指定。
[signal] void QDesignerFormWindowInterface::widgetUnmanaged(QWidget *widget)
每当表单上的某个控件变为非托管状态时,都会触发此信号。被释放的控件由widget 指定。
另请参阅 unmanageWidget() 和aboutToUnmanageWidget()。
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.