diff options
author | MohammadHossein Qanbari <mohammad.qanbari@qt.io> | 2024-01-08 16:41:56 +0100 |
---|---|---|
committer | MohammadHossein Qanbari <mohammad.qanbari@qt.io> | 2024-04-19 13:39:41 +0200 |
commit | 4e1a1f3697563124588d7d00089b15084220ca42 (patch) | |
tree | 6fc52dc5135c73257da50a283445a7c3c80b8ad4 /src/widgets/itemviews | |
parent | 3e426182e2e8122d96b208702faaf3177f3a3081 (diff) |
Convert "Color Editor Factory" Example to snippets
The color editor factory example is removed and part of the codes are
used as snippets.
Fixes: QTBUG-119985
Pick-to: 6.7 6.6
Change-Id: I421e473e7db09a5af7543b80b87a338d8ff2ab7e
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
Diffstat (limited to 'src/widgets/itemviews')
-rw-r--r-- | src/widgets/itemviews/qitemdelegate.cpp | 22 | ||||
-rw-r--r-- | src/widgets/itemviews/qitemeditorfactory.cpp | 8 | ||||
-rw-r--r-- | src/widgets/itemviews/qstyleditemdelegate.cpp | 19 |
3 files changed, 32 insertions, 17 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index e4a90278b4..d1c7bb3d58 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -257,15 +257,25 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const When subclassing QItemDelegate to create a delegate that displays items using a custom renderer, it is important to ensure that the delegate can - render items suitably for all the required states; e.g. selected, + render items suitably for all the required states; such as selected, disabled, checked. The documentation for the paint() function contains some hints to show how this can be achieved. - You can provide custom editors by using a QItemEditorFactory. The - \l{Color Editor Factory Example} shows how a custom editor can be - made available to delegates with the default item editor - factory. This way, there is no need to subclass QItemDelegate. An - alternative is to reimplement createEditor(), setEditorData(), + You can provide custom editors by using a QItemEditorFactory. The following + code shows how a custom editor can be made available to delegates with the + default item editor factory. + + \snippet code/src_gui_itemviews_qitemeditorfactory.cpp setDefaultFactory + + After the default factory has been set, all standard item delegates + will use it (also the delegates that were created before setting the + default factory). + + This way, you can avoid subclassing QItemDelegate, and all values of the + specified type (for example QMetaType::QDateTime) will be edited using the + provided editor (like \c{MyFancyDateTimeEdit} in the above example). + + An alternative is to reimplement createEditor(), setEditorData(), setModelData(), and updateEditorGeometry(). This process is described in the \l{A simple delegate}{Model/View Programming overview documentation}. diff --git a/src/widgets/itemviews/qitemeditorfactory.cpp b/src/widgets/itemviews/qitemeditorfactory.cpp index 609df364cf..70d11e1b38 100644 --- a/src/widgets/itemviews/qitemeditorfactory.cpp +++ b/src/widgets/itemviews/qitemeditorfactory.cpp @@ -120,7 +120,7 @@ Q_SIGNALS: Additional editors can be registered with the registerEditor() function. - \sa QStyledItemDelegate, {Model/View Programming}, {Color Editor Factory Example} + \sa QStyledItemDelegate, {Model/View Programming} */ /*! @@ -363,7 +363,7 @@ void QItemEditorFactory::setDefaultFactory(QItemEditorFactory *factory) to register widgets without the need to subclass QItemEditorCreatorBase. \sa QStandardItemEditorCreator, QItemEditorFactory, - {Model/View Programming}, {Color Editor Factory Example} + {Model/View Programming} */ /*! @@ -432,7 +432,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase() property, you should use QStandardItemEditorCreator instead. \sa QItemEditorCreatorBase, QStandardItemEditorCreator, - QItemEditorFactory, {Color Editor Factory Example} + QItemEditorFactory */ /*! @@ -488,7 +488,7 @@ QItemEditorCreatorBase::~QItemEditorCreatorBase() \snippet code/src_gui_itemviews_qitemeditorfactory.cpp 3 \sa QItemEditorCreatorBase, QItemEditorCreator, - QItemEditorFactory, QStyledItemDelegate, {Color Editor Factory Example} + QItemEditorFactory, QStyledItemDelegate */ /*! diff --git a/src/widgets/itemviews/qstyleditemdelegate.cpp b/src/widgets/itemviews/qstyleditemdelegate.cpp index 0587e8d0be..54c1fb4f52 100644 --- a/src/widgets/itemviews/qstyleditemdelegate.cpp +++ b/src/widgets/itemviews/qstyleditemdelegate.cpp @@ -137,12 +137,17 @@ public: instance provided by QItemEditorFactory is installed on all item delegates. You can set a custom factory using setItemEditorFactory() or set a new default factory with - QItemEditorFactory::setDefaultFactory(). It is the data stored in - the item model with the \l{Qt::}{EditRole} that is edited. See the - QItemEditorFactory class for a more high-level introduction to - item editor factories. The \l{Color Editor Factory Example}{Color - Editor Factory} example shows how to create custom editors with a - factory. + QItemEditorFactory::setDefaultFactory(). + + \snippet code/src_gui_itemviews_qitemeditorfactory.cpp setDefaultFactory + + After the new factory has been set, all standard item delegates + will use it (i.e, also delegates that were created before the new + default factory was set). + + It is the data stored in the item model with the \l{Qt::}{EditRole} + that is edited. See the QItemEditorFactory class for a more + high-level introduction to item editor factories. \section1 Subclassing QStyledItemDelegate @@ -204,7 +209,7 @@ public: documentation for details. \sa {Delegate Classes}, QItemDelegate, QAbstractItemDelegate, QStyle, - {Star Delegate Example}, {Color Editor Factory Example} + {Star Delegate Example} */ |