easymodel.widgetdelegate.WidgetDelegate

class easymodel.widgetdelegate.WidgetDelegate(parent=None)[source]

Bases: PySide.QtGui.QStyledItemDelegate

A delegate for drawing a arbitrary QWidget

When subclassing, reimplement:

Note

Make sure that the model returns the ItemIsEditable flag!

I recommend using one of the views in this module, because they issue click events, when an index is clicked.

Create a new abstract widget delegate that draws the given widget.

Parameters:
  • widget (QtGui.QWidget | None) – the widget to draw. If None, it behaves like a QtGui.QStyledItemDelegate
  • parent (QtCore.QObject) – the parent object
Raises:

None

__init__(parent=None)[source]

Create a new abstract widget delegate that draws the given widget.

Parameters:
  • widget (QtGui.QWidget | None) – the widget to draw. If None, it behaves like a QtGui.QStyledItemDelegate
  • parent (QtCore.QObject) – the parent object
Raises:

None

Methods

__init__([parent]) Create a new abstract widget delegate that draws the given widget.
blockSignals
childEvent
children
close_editors() Close all current editors
commit_close_editor(index[, endedithint]) Commit and close the editor
connect
connectNotify
createEditor(parent, option, index) Return the editor to be used for editing the data item with the given index.
create_editor_widget(parent, option, index) Return a editor widget for the given index.
create_widget([parent]) Return a widget that should get painted by the delegate
customEvent
deleteLater
disconnect
disconnectNotify
displayText
dumpObjectInfo
dumpObjectTree
dynamicPropertyNames
edit_widget(index) Return the current edit widget at the givent index if there is one
editorEvent
editor_destroyed([index]) Callback for when the editor widget gets destroyed.
emit
event
eventFilter
findChild
findChildren
helpEvent
inherits
initStyleOption
installEventFilter
isWidgetType
itemEditorFactory
killTimer
metaObject
moveToThread
objectName
paint(painter, option, index) Use the painter and style option to render the item specified by the item index.
parent
property
receivers
registerUserData
removeEventFilter
sender
senderSignalIndex
setEditorData
setItemEditorFactory
setModelData
setObjectName
setParent
setProperty
set_widget_index(index) Set the index for the widget.
signalsBlocked
sizeHint(option, index) Return the appropriate amount for the size of the widget
startTimer
thread
timerEvent
tr
trUtf8
updateEditorGeometry(editor, option, index) Make sure the editor is the same size as the widget

Attributes

EditNextItem
EditPreviousItem
NoHint
RevertModelCache
SubmitModelCache
closeEditor
commitData
destroyed
sizeHintChanged
staticMetaObject
widget Return the widget that is used by the delegate for drawing
keep_editor_size = None

If True, resize the editor at least to its size Hint size, or if the section allows is, bigger.

widget

Return the widget that is used by the delegate for drawing

Returns:widget
Return type:QtGui.QWidget
Raises:None
paint(painter, option, index)[source]

Use the painter and style option to render the item specified by the item index.

Parameters:
  • painter (QtGui.QPainter) – the painter to paint
  • option (QtGui.QStyleOptionViewItem) – the options for painting
  • index (QtCore.QModelIndex) – the index to paint
Returns:

None

Return type:

None

Raises:

None

sizeHint(option, index)[source]

Return the appropriate amount for the size of the widget

The widget will always be expanded to at least the size of the viewport.

Parameters:
  • option (QtGui.QStyleOptionViewItem) – the options for painting
  • index (QtCore.QModelIndex) – the index to paint
Returns:

None

Return type:

None

Raises:

None

set_widget_index(index)[source]

Set the index for the widget. The widget should retrieve data from the index and display it.

You might want use the same function as for WidgetDelegate.setEditorData().

Parameters:index (QtCore.QModelIndex) – the index to paint
Returns:None
Return type:None
Raises:None
create_widget(parent=None)[source]

Return a widget that should get painted by the delegate

You might want to use this in WidgetDelegate.create_editor_widget()

Parameters:parent (QtGui.QWidget | None) – the parent widget
Returns:The created widget | None
Return type:QtGui.QWidget | None
Raises:None
close_editors()[source]

Close all current editors

Returns:None
Return type:None
Raises:None
createEditor(parent, option, index)[source]

Return the editor to be used for editing the data item with the given index.

Note that the index contains information about the model being used. The editor’s parent widget is specified by parent, and the item options by option.

This will set auto fill background to True on the editor, because else, you would see The rendered delegate below.

Parameters:
  • parent (QtGui.QWidget) – the parent widget
  • option (QtGui.QStyleOptionViewItem) – the options for painting
  • index (QtCore.QModelIndex) – the index to paint
Returns:

The created widget | None

Return type:

QtGui.QWidget | None

Raises:

None

create_editor_widget(parent, option, index)[source]

Return a editor widget for the given index.

Parameters:
  • parent (QtGui.QWidget) – the parent widget
  • option (QtGui.QStyleOptionViewItem) – the options for painting
  • index (QtCore.QModelIndex) – the index to paint
Returns:

The created widget | None

Return type:

QtGui.QWidget | None

Raises:

None

commit_close_editor(index, endedithint=PySide.QtGui.QAbstractItemDelegate.EndEditHint.NoHint)[source]

Commit and close the editor

Call this method whenever the user finished editing.

Parameters:
  • index (QtCore.QModelIndex) – The index of the editor
  • endedithint (QtGui.QAbstractItemDelegate.EndEditHint) – Hints that the delegate can give the model and view to make editing data comfortable for the user
Returns:

None

Return type:

None

Raises:

None

edit_widget(index)[source]

Return the current edit widget at the givent index if there is one

Parameters:index (QtCore.QModelIndex) – The index of the editor
Returns:The editor widget | None
Return type:QtGui.QWidget | None
Raises:None
editor_destroyed(index=None, *args)[source]

Callback for when the editor widget gets destroyed. Set edit_widget to None.

Returns:None
Return type:None
Raises:None
updateEditorGeometry(editor, option, index)[source]

Make sure the editor is the same size as the widget

By default it can get smaller because does not expand over viewport size. This will make sure it will resize to the same size as the widget.

Parameters:
  • editor (QtGui.QWidget) – the editor to update
  • option (QtGui.QStyleOptionViewItem) – the options for painting
  • index (QtCore.QModelIndex) – the index to paint
Returns:

None

Return type:

None

Raises:

None

staticMetaObject = <PySide.QtCore.QMetaObject object>