Go to the documentation of this file.00001 import python_qt_binding.QtBindingHelper
00002 from QtCore import Qt
00003 from QtGui import QSpinBox, QItemDelegate
00004
00005 class IntegerSpinBoxDelegate(QItemDelegate):
00006
00007 def __init__(self, parent = None):
00008 super(IntegerSpinBoxDelegate, self).__init__(parent)
00009 self._minimum = None
00010 self._maximum = None
00011 self._suffix = None
00012 self._single_step = None
00013
00014 def setMinimum(self, minimum):
00015 self._minimum = minimum
00016
00017 def setMaximum(self, maximum):
00018 self._maximum = maximum
00019
00020 def setSuffix(self, suffix):
00021 self._suffix = suffix
00022
00023 def setSingleStep(self, single_step):
00024 self._single_step = single_step
00025
00026 def createEditor(self, parent, option, index):
00027 editor = self._create_editor(parent)
00028 if self._minimum is not None:
00029 editor.setMinimum(self._minimum)
00030 if self._maximum is not None:
00031 editor.setMaximum(self._maximum)
00032 if self._suffix is not None:
00033 editor.setSuffix(self._suffix)
00034 if self._single_step is not None:
00035 editor.setSingleStep(self._single_step)
00036 editor.installEventFilter(self)
00037 return editor
00038
00039 def _create_editor(self, parent):
00040 return QSpinBox(parent)
00041
00042 def setEditorData(self, editor, index):
00043 value = index.model().data(index, Qt.EditRole)
00044 editor.setValue(value)
00045
00046 def setModelData(self, editor, model, index):
00047 editor.interpretText()
00048 value = editor.value()
00049 model.setData(index, value, Qt.EditRole)
00050
00051 def updateEditorGeometry(self, editor, option, index):
00052 editor.setGeometry(option.rect)