diff options
Diffstat (limited to 'src/widgets/itemviews/qitemdelegate.cpp')
-rw-r--r-- | src/widgets/itemviews/qitemdelegate.cpp | 36 |
1 files changed, 23 insertions, 13 deletions
diff --git a/src/widgets/itemviews/qitemdelegate.cpp b/src/widgets/itemviews/qitemdelegate.cpp index 79ee203aca..d1c7bb3d58 100644 --- a/src/widgets/itemviews/qitemdelegate.cpp +++ b/src/widgets/itemviews/qitemdelegate.cpp @@ -257,17 +257,27 @@ 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(), - setModelData(), and updateEditorGeometry(). This process is - described in the \l{Spin Box Delegate Example}. + 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}. \section1 QStyledItemDelegate vs. QItemDelegate @@ -281,9 +291,7 @@ QSizeF QItemDelegatePrivate::doTextLayout(int lineWidth) const for either class should be equal unless the custom delegate needs to use the style for drawing. - \sa {Delegate Classes}, QStyledItemDelegate, QAbstractItemDelegate, - {Spin Box Delegate Example}, {Settings Editor Example}, - {Icons Example} + \sa {Delegate Classes}, QStyledItemDelegate, QAbstractItemDelegate */ /*! @@ -343,8 +351,10 @@ QString QItemDelegatePrivate::valueToText(const QVariant &value, const QStyleOpt For example, a selected item may need to be displayed differently to unselected items, as shown in the following code: - \snippet itemviews/pixelator/pixeldelegate.cpp 2 - \dots + \code + if (option.state & QStyle::State_Selected) + painter->fillRect(option.rect, option.palette.highlight()); + \endcode After painting, you should ensure that the painter is returned to its the state it was supplied in when this function was called. For example, |