QDesignerPropertyEditorInterface Class

QDesignerPropertyEditorInterface 类允许您查询和操作Qt Widgets Designer 的属性编辑器的当前状态。更多

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

公共函数

QDesignerPropertyEditorInterface(QWidget *parent, Qt::WindowFlags flags = {})
virtual ~QDesignerPropertyEditorInterface()
virtual QDesignerFormEditorInterface *core() const
virtual QString currentPropertyName() const = 0
virtual bool isReadOnly() const = 0
virtual QObject *object() const = 0

公共插槽

virtual void setObject(QObject *object) = 0
virtual void setPropertyValue(const QString &name, const QVariant &value, bool changed = true) = 0
virtual void setReadOnly(bool readOnly) = 0

信号

void propertyChanged(const QString &name, const QVariant &value)

详细说明

QDesignerPropertyEditorInterface 包含一系列函数,这些函数通常用于查询属性编辑器的当前状态,还包含几个用于操作属性编辑器状态的插槽。该接口还提供了一个信号propertyChanged() ,每当属性编辑器中的属性发生变化时就会发出该信号。信号的参数是发生变化的属性及其新值。

例如,在实现自定义 widget 插件时,可以将信号连接到自定义槽:

        auto *propertyEditor = formEditor->propertyEditor();

        connect(propertyEditor, &QDesignerPropertyEditorInterface::propertyChanged,
                this, &MyClass::checkProperty);

然后,当属于特定 widget 的指定属性发生变化时,自定义槽可以检查新值是否在我们想要的范围内:

        void checkProperty(const QString &property, const QVariant &value)
        {
            auto *propertyEditor = formEditor->propertyEditor();

            auto *object = propertyeditor->object();
            auto *widget = qobject_cast<MyCustomWidget *>(object);

            if (widget && property == aProperty && value != expectedValue)
                {...}
        }

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

访问属性编辑器的函数包括:core() 函数,用于获取表单编辑器的接口;currentPropertyName() 函数,用于返回属性编辑器中当前选定属性的名称;object() 函数,用于返回Qt Widgets Designer 工作区中当前选定的对象;以及isReadOnly() 函数,用于在属性编辑器受写保护时返回 true(否则返回 false)。

操纵属性编辑器状态的槽是setObject() 槽(可用于更改Qt Widgets Designer 工作区中的当前选定对象)、setPropertyValue() 槽(用于更改给定属性的值)和setReadOnly() 槽(用于控制属性编辑器的写保护)。

另请参阅 QDesignerFormEditorInterface

成员函数文档

[explicit] QDesignerPropertyEditorInterface::QDesignerPropertyEditorInterface(QWidget *parent, Qt::WindowFlags flags = {})

使用给定的parent 和指定的窗口flags 构建属性编辑器界面。

[virtual noexcept] QDesignerPropertyEditorInterface::~QDesignerPropertyEditorInterface()

销毁属性编辑器界面。

[virtual] QDesignerFormEditorInterface *QDesignerPropertyEditorInterface::core() const

返回Qt Widgets Designer 当前QDesignerFormEditorInterface 对象的指针。

[pure virtual] QString QDesignerPropertyEditorInterface::currentPropertyName() const

返回属性编辑器中当前选中属性的名称。

另请参阅 setPropertyValue()。

[pure virtual] bool QDesignerPropertyEditorInterface::isReadOnly() const

如果属性编辑器受写保护,则返回 true;否则返回 false。

另请参阅 setReadOnly()。

[pure virtual] QObject *QDesignerPropertyEditorInterface::object() const

返回Qt Widgets Designer 工作区中当前选中的对象。

另请参阅 setObject().

[signal] void QDesignerPropertyEditorInterface::propertyChanged(const QString &name, const QVariant &value)

每当属性编辑器中的某个属性发生变化时,就会发出该信号。改变的属性及其新值分别由namevalue 指定。

另请参见 setPropertyValue().

[pure virtual slot] void QDesignerPropertyEditorInterface::setObject(QObject *object)

Qt Widgets Designer 工作区中当前选定的对象更改为object

另请参阅 object() 。

[pure virtual slot] void QDesignerPropertyEditorInterface::setPropertyValue(const QString &name, const QVariant &value, bool changed = true)

name 指定的属性值设置为value

此外,该属性在属性编辑器中将被标记为changed ,即其值不同于默认值。

另请参阅 currentPropertyName() 和propertyChanged() 。

[pure virtual slot] void QDesignerPropertyEditorInterface::setReadOnly(bool readOnly)

如果readOnly 为 true,属性编辑器将被设置为写保护;否则写保护将被取消。

另请参阅 isReadOnly().

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