QDesignerWidgetBoxInterface Class

QDesignerWidgetBoxInterface 类允许您控制Qt Widgets Designer widget 框的内容。更多

Header: #include <QDesignerWidgetBoxInterface>
CMake: find_package(Qt6 REQUIRED COMPONENTS Designer)
target_link_libraries(mytarget PRIVATE Qt6::Designer)
qmake: QT += designer
继承: QWidget

公共函数

QDesignerWidgetBoxInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())
virtual ~QDesignerWidgetBoxInterface()
virtual QString fileName() const = 0
virtual bool load() = 0
virtual bool save() = 0
virtual void setFileName(const QString &fileName) = 0

详细说明

QDesignerWidgetBoxInterface 包含一系列函数,通常用于操作Qt Widgets Designer 的 widget 框内容。

Qt Widgets Designer QDesignerWidgetBoxInterface 使用 XML 文件填充其 widget 框。该文件的名称是 widget 框的属性之一,您可以使用 () 函数获取该名称。fileName

QDesignerWidgetBoxInterface 还提供了save() 函数,可将 widget 框的内容保存到 widget 框文件名属性指定的文件中。如果您在未调用save() 函数的情况下对窗口小部件框进行了更改(例如将窗口小部件放入窗口小部件框中),则只需调用load() 函数即可恢复原始内容:

        auto *widgetBox = formEditor->widgetBox();

        widgetBox->load();

QDesignerWidgetBoxInterface 类不打算直接实例化。您可以使用QDesignerFormEditorInterface::widgetBox() 函数获取Qt Designer 的部件框接口。QDesignerCustomWidgetInterface::initialize() 函数的参数提供了指向Qt Widgets Designer 当前QDesignerFormEditorInterface 对象(上例中为formEditor )的指针。在实现自定义 widget 插件时,您必须子类化QDesignerCustomWidgetInterface ,以便向Qt Widgets Designer 公开您的插件。

如果您想保存更改,同时保留原始内容,可以使用save() 函数和setFileName() 函数将更改保存到另一个文件中。记住先保存原始文件的名称:

        QString originalFile = widgetBox->fileName();

        widgetBox->setFileName("myWidgetBox.xml");
        widgetBox->save();

然后,您可以通过将文件名重设为原始文件并调用load() 来恢复 widget 框的原始内容:

        widgetBox->setFileName(originalFile);
        widgetBox->load();

用类似的方法,您以后就可以使用定制的 XML 文件了:

        if (widgetBox->filename() != "myWidgetBox.xml") {
            widgetBox->setFileName("myWidgetBox.xml");
            widgetBox->load();
        }

另请参见 QDesignerFormEditorInterface

成员函数文档

[explicit] QDesignerWidgetBoxInterface::QDesignerWidgetBoxInterface(QWidget *parent = nullptr, Qt::WindowFlags flags = Qt::WindowFlags())

使用给定的parent 和指定的窗口flags 构建部件盒界面。

[virtual noexcept] QDesignerWidgetBoxInterface::~QDesignerWidgetBoxInterface()

销毁 widget 框界面。

[pure virtual] QString QDesignerWidgetBoxInterface::fileName() const

返回Qt Widgets Designer 当前用于填充 widget 框的 XML 文件名称。

另请参阅 setFileName()。

[pure virtual] bool QDesignerWidgetBoxInterface::load()

通过加载(或重新加载)当前指定的 XML 文件来填充Qt Widgets Designer 的 widget 框。如果文件加载成功,则返回 true;否则返回 false。

另请参阅 setFileName().

[pure virtual] bool QDesignerWidgetBoxInterface::save()

Qt Widgets Designer widget 框的内容保存到fileName() 函数指定的文件中。如果内容保存成功,则返回 true;否则返回 false。

另请参阅 fileName() 和setFileName()。

[pure virtual] void QDesignerWidgetBoxInterface::setFileName(const QString &fileName)

Qt Widgets Designer 用来填充 widget 框的 XML 文件设置为fileName 。必须调用load() 才能用新的 XML 文件更新 widget 框。

另请参阅 fileName() 和load()。

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