QDesignerWidgetBoxInterface Class
QDesignerWidgetBoxInterface 类允许您控制Qt Widgets Designer 的小部件框中的内容。更多内容...
| 头文件: | #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() override |
| virtual QString | fileName() const = 0 |
| virtual bool | load() = 0 |
| virtual bool | save() = 0 |
| virtual void | setFileName(const QString &fileName) = 0 |
详细描述
QDesignerWidgetBoxInterface 包含一组函数,通常用于操作Qt Widgets Designer 的控件框内容。
Qt Widgets Designer fileName 使用XML文件来填充其控件框。该文件的名称是控件框的属性之一,您可以使用 ()函数获取该名称。
QDesignerWidgetBoxInterface 还提供了save() 函数,该函数将控件框的内容保存到由控件框的文件名属性指定的文件中。 如果您对控件框进行了修改(例如将控件拖放到控件框中),但未调用save()函数,只需简单地调用load()函数即可恢复原始内容:
auto *widgetBox = formEditor->widgetBox();
widgetBox->load();QDesignerWidgetBoxInterface 类不适用于直接实例化。 您可以使用QDesignerFormEditorInterface::widgetBox()函数获取Qt Designer 的控件框接口。QDesignerCustomWidgetInterface::initialize()函数的参数会提供指向Qt Widgets Designer 当前QDesignerFormEditorInterface 对象(如上例中的formEditor )的指针。在实现自定义控件插件时,您必须继承QDesignerCustomWidgetInterface 类,以便将您的插件暴露给Qt Widgets Designer 。
如果您希望保存更改,同时保留原始内容,可以使用save() 函数结合setFileName() 函数,将更改保存到另一个文件中。请记住先存储原始文件的名称:
QString originalFile = widgetBox->fileName();
widgetBox->setFileName("myWidgetBox.xml");
widgetBox->save();然后,您可以通过将文件名重置为原始文件名并调用load() 来恢复小部件框的原始内容:
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 构建一个控件框界面。
[override virtual noexcept] QDesignerWidgetBoxInterface::~QDesignerWidgetBoxInterface()
销毁小部件框界面。
[pure virtual] QString QDesignerWidgetBoxInterface::fileName() const
返回Qt Widgets Designer 当前用于填充其控件框的XML文件的名称。
另请参阅 setFileName()。
[pure virtual] bool QDesignerWidgetBoxInterface::load()
通过加载(或重新加载)当前指定的 XML 文件,将内容填充到Qt Widgets Designer 的控件框中。如果文件加载成功,则返回 true;否则返回 false。
另请参阅 setFileName()。
[pure virtual] bool QDesignerWidgetBoxInterface::save()
将Qt Widgets Designer 的小部件框中的内容保存到由fileName()函数指定的文件中。如果内容保存成功,则返回true;否则返回false。
另请参阅 fileName() 和setFileName()。
[pure virtual] void QDesignerWidgetBoxInterface::setFileName(const QString &fileName)
将Qt Widgets Designer 用于填充其控件框的XML文件设置为fileName 。您必须调用load()方法,才能使用新的XML文件更新控件框。
© 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.