From 4e1a1f3697563124588d7d00089b15084220ca42 Mon Sep 17 00:00:00 2001 From: MohammadHossein Qanbari Date: Mon, 8 Jan 2024 16:41:56 +0100 Subject: 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 --- src/widgets/itemviews/qitemdelegate.cpp | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) (limited to 'src/widgets/itemviews/qitemdelegate.cpp') 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}. -- cgit v1.2.3