QStandardItemEditorCreator Class
template <typename T> class QStandardItemEditorCreatorQStandardItemEditorCreator 类提供了注册部件的可能性,而无需对QItemEditorCreatorBase 进行子类化。更多
Header: | #include <QStandardItemEditorCreator> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
继承: | QItemEditorCreatorBase |
公共函数
重新实现的公共函数
virtual QWidget * | createWidget(QWidget *parent) const override |
virtual QByteArray | valuePropertyName() const override |
详细说明
该模板类可方便地注册部件,而无需子类化QItemEditorCreatorBase 。
示例
QItemEditorFactory *editorFactory = new QItemEditorFactory; QItemEditorCreatorBase *creator = new QStandardItemEditorCreator<MyFancyDateTimeEdit>(); editorFactory->registerEditor(QMetaType::QDateTime, creator);
通过QStyledItemDelegate::setItemEditorFactory() 在项目委托中设置上面创建的editorFactory
,可以确保所有QMetaType::QDateTime 类型的值都将在MyFancyDateTimeEdit
中编辑。
编辑器必须提供一个包含编辑数据的用户属性。QStyledItemDelegates 将使用该属性来设置和检索数据(使用 Qt XML 的元对象系统)。您可以使用 USER 关键字设置用户属性:
Q_PROPERTY(QColor color READ color WRITE setColor USER true)
另请参阅 QItemEditorCreatorBase,QItemEditorCreator,QItemEditorFactory, 和QStyledItemDelegate 。
成员函数文档
QStandardItemEditorCreator::QStandardItemEditorCreator()
构造一个编辑器创建者对象。
[override virtual]
QWidget *QStandardItemEditorCreator::createWidget(QWidget *parent) const
重实现:QItemEditorCreatorBase::createWidget(QWidget *parent) const.
[override virtual]
QByteArray QStandardItemEditorCreator::valuePropertyName() const
重实现:QItemEditorCreatorBase::valuePropertyName() const.
© 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.