CopperSpice API
1.9.2
|
The QAbstractItemDelegate class is used to display and edit data items from a model. More...
Public Types | |
enum | EndEditHint |
Public Signals | |
void | closeEditor (QWidget *editor, QAbstractItemDelegate::EndEditHint hint=NoHint) |
void | commitData (QWidget *editor) |
void | sizeHintChanged (const QModelIndex &index) |
Public Signals inherited from QObject | |
void | destroyed (QObject *obj=nullptr) |
void | objectNameChanged (const QString &objectName) |
Public Methods | |
QAbstractItemDelegate (QObject *parent=nullptr) | |
virtual | ~QAbstractItemDelegate () |
virtual QWidget * | createEditor (QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const |
virtual void | destroyEditor (QWidget *editor, const QModelIndex &index) const |
virtual bool | editorEvent (QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) |
virtual bool | helpEvent (QHelpEvent *event, QAbstractItemView *view, const QStyleOptionViewItem &option, const QModelIndex &index) |
virtual void | paint (QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const = 0 |
virtual void | setEditorData (QWidget *editor, const QModelIndex &index) const |
virtual void | setModelData (QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const |
virtual QSize | sizeHint (const QStyleOptionViewItem &option, const QModelIndex &index) const = 0 |
virtual void | updateEditorGeometry (QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const |
Public Methods inherited from QObject | |
QObject (QObject *parent=nullptr) | |
~QObject () | |
bool | blockSignals (bool block) |
const QList< QObject * > & | children () const |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | connect (const QObject *sender, const QString &signalMethod, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
bool | disconnect (const QObject *receiver, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod, const QString &location, const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
bool | disconnect (const QString &signalMethod=QString (), const QObject *receiver=nullptr, const QString &slotMethod=QString ()) const |
void | dumpObjectInfo () |
void | dumpObjectTree () |
QList< QString > | dynamicPropertyNames () const |
virtual bool | event (QEvent *event) |
virtual bool | eventFilter (QObject *watched, QEvent *event) |
template<typename T > | |
T | findChild (const QString &childName=QString ()) const |
template<class T > | |
QList< T > | findChildren (const QRegularExpression ®Exp, Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
template<class T > | |
QList< T > | findChildren (const QString &childName=QString (), Qt::FindChildOptions options=Qt::FindChildrenRecursively) const |
bool | inherits (const QString &className) const |
void | installEventFilter (QObject *filterObj) |
bool | isWidgetType () const |
bool | isWindowType () const |
void | killTimer (int id) |
const QMetaObject * | metaObject () const |
void | moveToThread (QThread *targetThread) |
QString | objectName () const |
QObject * | parent () const |
template<class T = QVariant> | |
T | property (const QString &name) const |
void | removeEventFilter (QObject *obj) |
void | setObjectName (const QString &name) |
void | setParent (QObject *parent) |
bool | setProperty (const QString &name, const QVariant &value) |
bool | signalsBlocked () const |
int | startTimer (int interval, Qt::TimerType timerType=Qt::CoarseTimer) |
QThread * | thread () const |
Static Public Methods | |
static QString | elidedText (const QFontMetrics &fontMetrics, int width, Qt::TextElideMode mode, const QString &text) |
Static Public Methods inherited from QObject | |
static bool | connect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection, const QString &location=QString ()) |
static bool | connect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod, Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...), Qt::ConnectionType type=Qt::AutoConnection) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | connect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotLambda, Qt::ConnectionType type=Qt::AutoConnection) |
static bool | disconnect (const QObject *sender, const QMetaMethod &signalMethod, const QObject *receiver, const QMetaMethod &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, const QString &signalMethod, const QString &location, const QObject *receiver, const QString &slotMethod) |
static bool | disconnect (const QObject *sender, std::nullptr_t, const QObject *receiver, std::nullptr_t) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class SlotClass , class... SlotArgs, class SlotReturn > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, SlotReturn (SlotClass::*slotMethod)(SlotArgs...)) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, std::nullptr_t slotMethod=nullptr) |
template<class Sender , class SignalClass , class... SignalArgs, class Receiver , class T > | |
static bool | disconnect (const Sender *sender, void (SignalClass::*signalMethod)(SignalArgs...), const Receiver *receiver, T slotMethod) |
static QMetaObject & | staticMetaObject () |
static QString | tr (const char *text, const char *comment=nullptr, std::optional< int > numArg=std::optional< int >()) |
Additional Inherited Members | |
Public Slots inherited from QObject | |
void | deleteLater () |
Protected Methods inherited from QObject | |
virtual void | childEvent (QChildEvent *event) |
virtual void | connectNotify (const QMetaMethod &signalMethod) const |
virtual void | customEvent (QEvent *event) |
virtual void | disconnectNotify (const QMetaMethod &signalMethod) const |
bool | isSignalConnected (const QMetaMethod &signalMethod) const |
int | receivers (const QString &signal) const |
QObject * | sender () const |
int | senderSignalIndex () const |
virtual void | timerEvent (QTimerEvent *event) |
Properties inherited from QObject | |
objectName | |
Related Functions inherited from QObject | |
T | qobject_cast (QObject *object) |
QObjectList | |
The QAbstractItemDelegate class is used to display and edit data items from a model. It provides the interface and common functionality for delegates in the model/view architecture. Delegates display individual items in views and handle the editing of model data.
To render an item in a custom way, you must implement paint() and sizeHint(). The QItemDelegate class provides default implementations for these functions. If you do not need custom rendering, subclass that class instead.
The following example shows how to draw a progress bar. The WidgetDelegate class inherits from QStyledItemDelegate. The actual drawing occurs in paint() based on the call to drawControl(). A QStyleOptionProgressBar is initialized and then passed to the current QStyle to draw it.
To provide custom editing there are two approaches that can be used.
The first approach is to create an editor widget and display it directly on top of the item. To do this you must reimplement createEditor() to provide an editor widget, setEditorData() to populate the editor with the data from the model and setModelData() so the delegate can update the model with data from the editor.
The second approach is to handle user events directly by reimplementing editorEvent().
This enum describes the different hints that the delegate can give to the model and view components to make editing data in a model a comfortable experience for the user.
Constant | Value | Description |
---|---|---|
QAbstractItemDelegate::NoHint | 0 | There is no recommended action to be performed. |
These hints let the delegate influence the behavior of the view:
Constant | Value | Description |
---|---|---|
QAbstractItemDelegate::EditNextItem | 1 | The view should use the delegate to open an editor on the next item in the view. |
QAbstractItemDelegate::EditPreviousItem | 2 | The view should use the delegate to open an editor on the previous item in the view. |
Custom views may interpret the concepts of next and previous differently.
The following hints are most useful when models are used that cache data, such as those that manipulate data locally in order to increase performance or conserve network bandwidth.
Constant | Value | Description |
---|---|---|
QAbstractItemDelegate::SubmitModelCache | 3 | If the model caches data, it should write out cached data to the underlying data store. |
QAbstractItemDelegate::RevertModelCache | 4 | If the model caches data, it should discard cached data and replace it with data from the underlying data store. |
Although models and views should respond to these hints in appropriate ways, custom components may ignore any or all of them if they are not relevant.
|
explicit |
Construct a new abstract item delegate with the given parent.
|
virtual |
Destroys the abstract item delegate.
|
signal |
This signal is emitted when the user has finished editing an item.
The specified editor represents the widget which was used to modify the item.
The hint provides a way for the delegate to influence how the model and view behave after editing is completed. It indicates to these components what action should be performed next to provide a comfortable editing experience for the user. For example, if EditNextItem is specified the view should use a delegate to open an editor on the next item in the model.
|
signal |
This signal must be emitted when the editor widget has completed the edit process. The slot method is responsible for calling the setEditorData() method to save the data back into the model.
|
virtual |
Returns the editor widget which should be used for editing the data with the given index. The editor's parent widget is specified by parent and the item options by option. The base implementation returns a nullptr.
To use custom editing you will need to reimplement this method in a custom delegate class. The returned editor widget should set the Qt::StrongFocus flag, otherwise QMouseEvents received by the widget will propagate to the view.
Reimplemented in QItemDelegate::createEditor(), QStyledItemDelegate::createEditor(), QSqlRelationalDelegate::createEditor()
|
virtual |
Called when the editor is no longer needed for editing the data item with the given index and should be destroyed. The default behavior is a call to deleteLater on the editor. It is possible e.g. to avoid this delete by reimplementing this method.
|
virtual |
When editing of an item starts this method is called with the event that triggered the editing, the model, the index of the item, and the option used for rendering the item. Mouse events are sent to editorEvent() even if they do not start editing of the item. This can, for instance, be useful if you wish to open a context menu when the right mouse button is pressed on an item.
The base implementation returns false (indicating that it has not handled the event).
Reimplemented in QItemDelegate::editorEvent(), QStyledItemDelegate::editorEvent()
|
deprecatedstatic |
If you have code similar to the following rewrite as shown.
|
virtual |
Whenever a help event occurs, this method is called with the given event, view, option, and the index that corresponds to the item where the event occurs. Returns true if the delegate can handle the event, otherwise returns false. A return value of true indicates that the data obtained using the index had the required role.
For QEvent::ToolTip and QEvent::WhatsThis events that were handled successfully, the relevant popup may be shown depending on the user's system configuration.
|
pure virtual |
This pure abstract function must be reimplemented if you want to provide custom rendering. Use the painter and style option to render the item specified by the item index.
If you reimplement this method, also reimplement sizeHint().
Implemented in QItemDelegate::paint(), QStyledItemDelegate::paint()
|
virtual |
Sets the contents of the given editor to the data for the item at the given index. The index contains information about the model being used.
The base implementation does nothing. If you want custom editing you will need to reimplement this function.
Reimplemented in QItemDelegate::setEditorData(), QStyledItemDelegate::setEditorData(), QSqlRelationalDelegate::setEditorData()
|
virtual |
Sets the data for the item at the given index in the model to the contents of the given editor.
The base implementation does nothing. If you want custom editing you will need to reimplement this function.
Reimplemented in QItemDelegate::setModelData(), QStyledItemDelegate::setModelData(), QSqlRelationalDelegate::setModelData()
|
pure virtual |
This pure abstract method must be reimplemented if you want to provide custom rendering. The options are specified by option and the model item by index.
If you reimplement this you must also reimplement paint().
Implemented in QItemDelegate::sizeHint(), QStyledItemDelegate::sizeHint()
|
signal |
This signal must be emitted when the sizeHint() of index changed. Views automatically connect to this signal and relayout items as necessary.
|
virtual |
Updates the geometry of the editor for the item with the given index to match the rectangle specified in option. If the item has an internal layout, the editor will be laid out accordingly. The index contains information about the model being used.
The base implementation for this method does nothing. If you want custom editing you must reimplement this method.
Reimplemented in QItemDelegate::updateEditorGeometry(), QStyledItemDelegate::updateEditorGeometry()