本页内容

QItemEditorCreator Class

template <typename T> class QItemEditorCreator

QItemEditorCreator 类使得无需继承QItemEditorCreatorBase 即可创建项目编辑器生成器的基类。更多内容...

头文件: #include <QItemEditorCreator>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承自: QItemEditorCreatorBase

公共函数

QItemEditorCreator(const QByteArray &valuePropertyName)

重新实现的公共函数

virtual QWidget *createWidget(QWidget *parent) const override
virtual QByteArray valuePropertyName() const override

详细说明

QItemEditorCreator<T> 是一个便捷模板类,其中T 指定了控件类型。它使用该模板类为QItemEditorFactory 创建编辑器。这样一来,就无需继承QItemEditorCreatorBase 了。

QItemEditorCreator<MyEditor> *itemCreator =
    new QItemEditorCreator<MyEditor>("myProperty");

QItemEditorFactory *factory = new QItemEditorFactory;

构造函数接受包含编辑数据的属性的名称。随后,QStyledItemDelegate 可以在设置和检索编辑数据时通过名称访问该属性。仅当您的编辑器未定义用户属性(即未在Q_PROPERTY 宏中使用USER关键字)时,才应使用此类。如果控件具有用户属性,则应改用QStandardItemEditorCreator 。

另请参阅 QItemEditorCreatorBase 、QStandardItemEditorCreator 和QItemEditorFactory 。

成员函数文档

[explicit] QItemEditorCreator::QItemEditorCreator(const QByteArray &valuePropertyName)

使用 `valuePropertyName ` 作为用于编辑的属性名称,构建一个编辑器创建器对象。QStyledItemDelegate 在设置和获取编辑器数据时会使用该属性名称。

请注意,只有当编辑器控件未定义用户属性时,才会使用 `valuePropertyName `。

[override virtual] QWidget *QItemEditorCreator::createWidget(QWidget *parent) const

重写了:QItemEditorCreatorBase::createWidget(QWidget *parent) const。

[override virtual] QByteArray QItemEditorCreator::valuePropertyName() const

重新实现了:QItemEditorCreatorBase::valuePropertyName() const。

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