QStandardItemEditorCreator Class
template <typename T> class QStandardItemEditorCreatorQStandardItemEditorCreator 类允许在不继承QItemEditorCreatorBase 的情况下注册小部件。更多内容...
| 头文件: | #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 |
详细说明
QStandardItemEditorCreator<T> 是一个便捷模板类,其中T 指定了控件类型。它允许在不继承QItemEditorCreatorBase 的情况下注册控件。
示例:
QItemEditorFactory *editorFactory = new QItemEditorFactory;
QItemEditorCreatorBase *creator = new QStandardItemEditorCreator<MyFancyDateTimeEdit>();
editorFactory->registerEditor(QMetaType::QDateTime, creator);通过QStyledItemDelegate::setItemEditorFactory()将上述创建的editorFactory 设置到项委托中,可确保所有类型为QMetaType::QDateTime 的值都将在MyFancyDateTimeEdit 中进行编辑。
编辑器必须提供一个用于存储编辑数据的用户属性。QStyledItemDelegate通过该属性(利用 Qt的元对象系统)来设置和获取数据。您需使用 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。
© 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.