KDE 4.7 PyKDE API Reference

- KDE's Python API

# KWidgetItemDelegate Class Reference

`from PyKDE4.kdeui import *`

Inherits: QAbstractItemDelegate → QObject

## Detailed Description

This class allows to create item delegates embedding simple widgets to interact with items. For instance you can add push buttons, line edits, etc. to your delegate and use them to modify the state of your model.

Since:
  4.1

## Methods
| __init__ (self, QAbstractItemView itemView, QObject parent=0)
[QEvent::Type] | blockedEventTypes (self, QWidget widget)
[QWidget] | createItemWidgets (self)
QPersistentModelIndex | focusedIndex (self)
QAbstractItemView | itemView (self)
| paintWidgets (self, QPainter painter, QStyleOptionViewItem option, QPersistentModelIndex index)
| setBlockedEventTypes (self, QWidget widget, [QEvent::Type] types)
| updateItemWidgets (self, [QWidget] widgets, QStyleOptionViewItem option, QPersistentModelIndex index)

## Method Documentation

__init__ | ( | self, |
|  | QAbstractItemView | itemView,
|  | QObject | parent=0
| ) |  |  |

Creates a new ItemDelegate to be used with a given itemview.

Parameters:

  | itemView | the item view the new delegate will monitor
  | parent | the parent of this delegate

[QEvent::Type] blockedEventTypes | ( | self, |
|  | QWidget | widget
| ) |  |  |

Retrieves the list of blocked event types for the given widget.

Parameters:

  | widget | the specified widget.

Returns:
  the list of blocked event types, can be empty if no events are blocked.

[QWidget] createItemWidgets | ( |  | self ) |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Creates the list of widgets needed for an item.

Note:
  No initialization of the widgets is supposed to happen here. The widgets will be initialized based on needs for a given item.

Note:
  If you want to connect some widget signals to any slot, you should do it here.

Note:
  If you want to know the index for which you are creating widgets, it is available as a QModelIndex Q_PROPERTY called "goya:creatingWidgetsForIndex". Ensure to add Q_DECLARE_METATYPE(QModelIndex) before your method definition to tell QVariant about QModelIndex.

Returns:
  the list of newly created widgets which will be used to interact with an item.

See also:
  updateItemWidgets()

QPersistentModelIndex focusedIndex | ( |  | self ) |

Retrieves the currently focused index. An invalid index if none is focused.

Returns:
  the current focused index, or QPersistentModelIndex() if none is focused.

QAbstractItemView itemView | ( |  | self ) |

Retrieves the item view this delegate is monitoring.

Returns:
  the item view this delegate is monitoring

paintWidgets | ( | self, |
|  | QPainter | painter,
|  | QStyleOptionViewItem | option,
|  | QPersistentModelIndex | index
| ) |  |  |

Paint the widgets of the item. This method is meant to be used in the paint() method of your item delegate implementation.

Parameters:

  | painter | the painter the widgets will be painted on.
  | option | the current set of style options for the view.
  | index | the model index of the item currently painted.

Warning:
  since 4.2 this method is not longer needed to be called. All widgets will kept updated without the need of calling paintWidgets() in your paint() event. For the widgets of a certain index to be updated your model has to emit dataChanged() on the indexes that want to be updated.

setBlockedEventTypes | ( | self, |
|  | QWidget | widget,
|  | [QEvent::Type] | types
| ) |  |  |

Sets the list of event types that a widget will block.

Blocked events are not passed to the view. This way you can prevent an item from being selected when a button is clicked for instance.

Parameters:

  | widget | the widget which must block events
  | types | the list of event types the widget must block

updateItemWidgets | ( | self, |
|  | [QWidget] | widgets,
|  | QStyleOptionViewItem | option,
|  | QPersistentModelIndex | index
| ) |  |  |

Abstract method:
  This method is abstract and can be overridden but not called directly.

Updates a list of widgets for its use inside of the delegate (painting or event handling).

Note:
  All the positioning and sizing should be done in item coordinates.

Warning:
  Do not make widget connections in here, since this method will be called very regularly.

Parameters:

  | widgets | the widgets to update
  | option | the current set of style options for the view.
  | index | the model index of the item currently manipulated.