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 的当前窗体窗口,这些窗体窗口由Qt Widgets Designerform window manager 控制。

如果要查找包含特定部件的窗体窗口,可以使用静态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() 函数的参数提供。在实现自定义 widget 插件时,您必须子类化QDesignerCustomWidgetInterface 类,以便向Qt Widgets Designer 公开您的插件。

获得表单窗口后,就可以查询其属性。例如,一个普通的自定义窗口小部件插件只能由Qt Widgets Designer 在其顶层进行管理,也就是说,其子窗口小部件都不能在Qt Widgets Designer 的工作区中调整大小。但是,QDesignerFormWindowInterface 提供了一些函数,让你可以控制一个窗口小部件是否应由Qt Widgets Designer 管理:

        if (formWindow->isManaged(myWidget))
            formWindow->manageWidget(myWidget->childWidget);

有关 widget 管理的函数的完整列表是:isManaged(),manageWidget() 和unmanageWidget().还有几个相关信号:widgetManaged(),widgetRemoved(),aboutToUnmanageWidget() 和widgetUnmanaged().

除了控制 widget 的管理外,您还可以使用selectWidget()、clearSelection() 和emitSelectionChanged() 函数以及selectionChanged() 信号来控制表单窗口中的当前选择。

您还可以使用absoluteDir() 获取窗体的存储位置信息,使用includeHints() 获取窗体的包含文件信息,使用layoutDefault() 、layoutFunction() 和pixmapFunction() 获取窗体的布局和像素图函数信息。您可以使用isDirty() 函数查找表单窗口是否已被修改(但未保存)。您可以检索author() 、contents() 、fileName() 、相关的comment() 和exportMacro() 、mainContainer()、features() 、grid() 和resourceFiles() 。

界面提供的函数和槽还允许您更改大部分信息。存储表单窗口的目录是个例外。最后,有几个信号与上述信息和窗体窗口的更改相关。

另请参阅 QDesignerFormWindowCursorInterface,QDesignerFormEditorInterface, 和QDesignerFormWindowManagerInterface

成员类型文档

枚举QDesignerFormWindowInterface::FeatureFlag
标志 QDesignerFormWindowInterface::Feature

该枚举描述了窗体窗口界面可用且可控制的功能。这些值用于查询窗体窗口,以确定它支持哪些功能:

常量描述
QDesignerFormWindowInterface::EditFeature0x01表格编辑
QDesignerFormWindowInterface::GridFeature0x02网格显示和网格快照编辑功能
QDesignerFormWindowInterface::TabOrderFeature0x04标签顺序管理
QDesignerFormWindowInterface::DefaultFeatureEditFeature | GridFeature支持默认功能(表单编辑和网格)

特征类型是QFlags<FeatureFlag> 的类型定义。它存储 FeatureFlag 值的 OR 组合。

另请参阅 hasFeature() 和features()。

enum QDesignerFormWindowInterface::ResourceFileSaveMode

该枚举描述了资源文件的保存方式。

常量说明
QDesignerFormWindowInterface::SaveAllResourceFiles0保存所有资源文件。
QDesignerFormWindowInterface::SaveOnlyUsedResourceFiles1保存表格使用的资源文件。
QDesignerFormWindowInterface::DontSaveResourceFiles2不保存资源文件。

成员函数文档

[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 类加载资源,使其可用于表单编辑。

在集成开发环境集成中,可激活项目资源(.qrc)文件列表,使其可用于Qt Widgets Designer

另请参阅 activeResourceFilePaths() 和QResource

[signal] void QDesignerFormWindowInterface::activated(QWidget *widget)

当表单上的部件被激活时,就会发出该信号。激活的 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

对当前表单进行检查,并返回有关潜在问题的富文本警告列表(例如,在未打开的表单上的顶层间隔)。

集成开发环境可在处理开始保存操作前调用此功能。

[pure virtual slot] void QDesignerFormWindowInterface::clearSelection(bool update = true)

清除表单窗口中的当前选择。如果update 为 true,则调用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

返回与窗口中当前显示的表单相关联的导出宏。导出宏在编译表单以创建 Widget 插件时使用。

另请参阅 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

返回描述当前显示表单的用户界面文件的文件名。

另请参见 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

返回包含主容器 widget 的表单。

[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

返回将包含在表单窗口相关用户界面文件中的头文件列表。

头文件可以是本地文件,即相对于项目目录的文件:"mywidget.h" ,也可以是全局文件,即 Qt 或编译器标准库的一部分:<QtGui/QWidget>

另请参见 setIncludeHints() 。

[pure virtual] bool QDesignerFormWindowInterface::isDirty() const

如果表单窗口是 "dirty"(已修改但未保存),则返回 true;否则返回 false。

另请参阅 setDirty().

[pure virtual] bool QDesignerFormWindowInterface::isManaged(QWidget *widget) const

如果指定的widget 由表单窗口管理,则返回 true;否则返回 false。

另请参阅 manageWidget().

[pure virtual] void QDesignerFormWindowInterface::layoutDefault(int *margin, int *spacing)

marginspacing 变量中填写表单默认布局的默认页边距和间距。

另请参阅 setLayoutDefault().

[pure virtual] void QDesignerFormWindowInterface::layoutFunction(QString *margin, QString *spacing)

marginspacing 变量中填入表格布局的当前页边距和间距。

另请参阅 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 字符串读取的数据设置表单内容,并返回操作是否成功。

另请参阅 contents()。

[pure virtual] bool QDesignerFormWindowInterface::setContents(QIODevice *device, QString *errorMessage = 0)

使用从给定device 获取的数据设置表单内容,并返回加载是否成功。如果加载失败,则在errorMessage 中返回错误信息。

数据可从QFile 对象或QIODevice 的任何其他子类中读取。

[pure virtual slot] void QDesignerFormWindowInterface::setDirty(bool dirty)

如果dirty 为 true,表单窗口将被标记为 dirty,即已修改但未保存。如果dirty 为 false,则认为表单窗口未修改。

另请参见 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)

设置表单布局的默认marginspacing

另请参阅 layoutDefault()。

[pure virtual] void QDesignerFormWindowInterface::setLayoutFunction(const QString &margin, const QString &spacing)

设置表单布局的marginspacing

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 由widget 指定。

另请参阅 manageWidget() 。

[signal] void QDesignerFormWindowInterface::widgetRemoved(QWidget *widget)

每当从表单中移除一个部件时,就会发出该信号。被移除的 widget 由widget 指定。

[signal] void QDesignerFormWindowInterface::widgetUnmanaged(QWidget *widget)

每当表单上的部件变为非托管时,就会发出该信号。新释放的 widget 由widget 指定。

另请参见 unmanageWidget() 和aboutToUnmanageWidget()。

© 2025 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.