QItemEditorCreatorBase Class

QItemEditorCreatorBase 类提供了一个抽象基类,在实现新的条目编辑器创建器时必须对其进行子类化。更多

Header: #include <QItemEditorCreatorBase>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承于

QItemEditorCreatorQStandardItemEditorCreator

公共函数

virtual ~QItemEditorCreatorBase()
virtual QWidget *createWidget(QWidget *parent) const = 0
virtual QByteArray valuePropertyName() const = 0

详细说明

QItemEditorCreatorBase 对象是专门的部件工厂,为QVariant 数据类型提供编辑器部件。QItemEditorFactory 使用它们来为QStyledItemDelegates 创建编辑器。创建者基地必须通过QItemEditorFactory::registerEditor() 注册。

编辑器应为其编辑的数据提供用户属性。然后,QItemDelagates 可使用 Qt 的元对象系统访问该属性,以设置和检索编辑数据。使用 USER 关键字可将属性设置为用户属性:

Q_PROPERTY(QColor color READ color WRITE setColor USER true)

如果编辑器没有提供用户属性,则必须从valuePropertyName() 返回属性名称;然后委托将使用该名称访问该属性。如果存在用户属性,项目代表将不会调用valuePropertyName() 。

QStandardItemEditorCreator 是一个方便的模板类,可用于注册部件,而无需子类化 QItemEditorCreatorBase。

另请参阅 QStandardItemEditorCreator,QItemEditorFactory, 以及模型/视图编程

成员函数文档

[virtual noexcept] QItemEditorCreatorBase::~QItemEditorCreatorBase()

销毁编辑器创建者对象。

[pure virtual] QWidget *QItemEditorCreatorBase::createWidget(QWidget *parent) const

返回具有给定parent 的编辑器部件。

在该类的子类中执行该函数时,必须使用指定的父 widget 构建并返回新的编辑器 widget。

[pure virtual] QByteArray QItemEditorCreatorBase::valuePropertyName() const

返回用于在创建者的编辑器部件中获取和设置值的属性名称。

在子类中执行此函数时,必须确保此函数指定的编辑器部件属性可以接受创建者注册的类型。例如,构造QCheckBox widget 来编辑布尔值的创建器将从该函数返回checkable 属性名,并且必须在QMetaType::Bool 类型的项目编辑器工厂中注册。

注意:自 Qt 4.2 起,项目委托会查询部件的用户属性,只有当部件没有用户属性时才会调用此函数。您可以通过重新实现QAbstractItemDelegate::setModelData() 和QAbstractItemDelegate::setEditorData() 来覆盖此行为。

另请参见 QMetaObject::userProperty() 和QItemEditorFactory::registerEditor()。

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