QDesignerPropertyEditorInterface Class
QDesignerPropertyEditorInterface 类允许您查询和操作Qt Widgets Designer 属性编辑器的当前状态。更多内容...
| 头文件: | #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() override |
| 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(),每当属性编辑器中的属性发生变化时,该信号就会被触发。该信号的参数是发生变化的属性及其新值。
例如,在实现自定义小部件插件时,您可以将该信号连接到自定义槽:
auto *propertyEditor = formEditor->propertyEditor();
connect(propertyEditor, &QDesignerPropertyEditorInterface::propertyChanged,
this, &MyClass::checkProperty);这样,当某个特定小部件的指定属性发生变化时,自定义槽即可检查新值是否在我们期望的范围内:
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 )的指针。在实现自定义小部件插件时,你必须继承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 ,构建一个属性编辑器界面。
[override 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)
每当属性编辑器中的属性发生变化时,都会触发此信号。发生变化的属性及其新值分别由name 和value 指定。
另请参阅 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 为真,则属性编辑器被设为只读;否则,将取消只读保护。
另请参阅 isReadOnly()。
© 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.