QItemDelegate Class Reference |
Role | Accepted Types |
---|---|
Qt::BackgroundColorRole | QColor |
Qt::CheckStateRole | Qt::CheckState |
Qt::DecorationRole | QIcon and QColor |
Qt::DisplayRole | QString and types with a string representation |
Qt::EditRole | See QItemEditorFactory for details |
Qt::FontRole | QFont |
Qt::SizeHintRole | QSize |
Qt::TextAlignmentRole | Qt::Alignment |
Qt::TextColorRole | QColor |
If the default delegate does not allow the level of customization that you need, it is possible to subclass QItemDelegate to implement the desired behavior.
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, disabled, checked. The documentation for the paint() function contains some hints to show how this can be achieved.
See also Model/View Programming and QAbstractItemDelegate.
Constructs an item delegate with the given parent.
Destroys the item delegate.
Returns the widget used to edit the item specified by index for editing. The parent widget and style option are used to control how the editor widget appears.
Reimplemented from QAbstractItemDelegate.
See also QAbstractItemDelegate::createEditor().
Renders a check indicator within the rectangle specified by rect, using the given painter and style option, using the given state.
Renders the decoration pixmap within the rectangle specified by rect using the given painter and style option.
Renders the item view text within the rectangle specified by rect using the given painter and style option.
Renders the region within the rectangle specified by rect, indicating that it has the focus, using the given painter and style option.
If the object is the current editor: if the event is an Esc key press the current edit is cancelled and ended, or if the event is an Enter or Return key press the current edit is accepted and ended. If editing is ended the event filter returns true to signify that it has handled the event; in all other cases it does nothing and returns false to signify that the event hasn't been handled.
Reimplemented from QObject.
See also closeEditor().
Returns the editor factory used by the item delegate. If no editor factory is set, the function will return null.
See also setItemEditorFactory().
Renders the delegate using the given painter and style option for the item specified by index.
When reimplementing this function in a subclass, you should update the area held by the option's rect variable, using the option's state variable to determine the state of the item to be displayed, and adjust the way it is painted accordingly.
For example, a selected item may need to be displayed differently to unselected items, as shown in the following code:
if (option.state & QStyle::State_Selected) painter->setBrush(option.palette.highlight()); else ...
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, it may be useful to call QPainter::save() before painting and QPainter::restore() afterwards.
Reimplemented from QAbstractItemDelegate.
See also QStyle::State.
Sets the data to be displayed and edited by the editor for the item specified by index.
Reimplemented from QAbstractItemDelegate.
Sets the editor factory to be used by the item delegate to be the factory specified. If no editor factory is set, the item delegate will use the default editor factory.
See also itemEditorFactory().
Sets the data for the specified model and item index from that supplied by the editor.
Reimplemented from QAbstractItemDelegate.
Returns the size needed by the delegate to display the item specified by index, taking into account the style information provided by option.
Reimplemented from QAbstractItemDelegate.
Updates the editor for the item specified by index according to the style option given.
Reimplemented from QAbstractItemDelegate.
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 4.1 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com