easymodel.widgetdelegate.WidgetDelegate¶
-
class
easymodel.widgetdelegate.WidgetDelegate(parent=None)[source]¶ Bases:
PySide.QtGui.QStyledItemDelegateA delegate for drawing a arbitrary QWidget
When subclassing, reimplement:
WidgetDelegate.set_widget_index()WidgetDelegate.create_widget()WidgetDelegate.create_editor_widget()WidgetDelegate.setEditorData()WidgetDelegate.setModelData()
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 aQtGui.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 aQtGui.QStyledItemDelegate - parent (
QtCore.QObject) – the parent object
Raises: None
- widget (
Methods
__init__([parent])Create a new abstract widget delegate that draws the given widget. blockSignalschildEventchildrenclose_editors()Close all current editors commit_close_editor(index[, endedithint])Commit and close the editor connectconnectNotifycreateEditor(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 customEventdeleteLaterdisconnectdisconnectNotifydisplayTextdumpObjectInfodumpObjectTreedynamicPropertyNamesedit_widget(index)Return the current edit widget at the givent index if there is one editorEventeditor_destroyed([index])Callback for when the editor widget gets destroyed. emiteventeventFilterfindChildfindChildrenhelpEventinheritsinitStyleOptioninstallEventFilterisWidgetTypeitemEditorFactorykillTimermetaObjectmoveToThreadobjectNamepaint(painter, option, index)Use the painter and style option to render the item specified by the item index. parentpropertyreceiversregisterUserDataremoveEventFiltersendersenderSignalIndexsetEditorDatasetItemEditorFactorysetModelDatasetObjectNamesetParentsetPropertyset_widget_index(index)Set the index for the widget. signalsBlockedsizeHint(option, index)Return the appropriate amount for the size of the widget startTimerthreadtimerEventtrtrUtf8updateEditorGeometry(editor, option, index)Make sure the editor is the same size as the widget Attributes
EditNextItemEditPreviousItemNoHintRevertModelCacheSubmitModelCachecloseEditorcommitDatadestroyedsizeHintChangedstaticMetaObjectwidgetReturn 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.QWidgetRaises: 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: Raises: None
- painter (
-
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: Raises: None
- option (
-
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 paintReturns: 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 widgetReturns: The created widget | None Return type: QtGui.QWidget| NoneRaises: 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| NoneRaises: 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| NoneRaises: 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: Raises: None
- index (
-
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 editorReturns: The editor widget | None Return type: QtGui.QWidget| NoneRaises: 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: Raises: None
- editor (
-
staticMetaObject= <PySide.QtCore.QMetaObject object>¶