Details
-
Bug
-
Resolution: Cannot Reproduce
-
Not Evaluated
-
None
-
1.2.x
-
None
-
Python 2.7.3, PySide 1.1.2, Linux
Description
When reimplementing paint in a subclass. Use the initStyleOption() to set up the option in the same way as the QStyledItemDelegate; the option will always be an instance of QStyleOptionViewItemV4. Please see its class description for information on its contents.
Qt doc reference: http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html#paint
Works as expected in PyQt4.
Sample code
–
-# - coding: utf-8
from PySide import QtCore, QtGui
#from PyQt4 import QtCore, QtGui
class TaskItemDelegate(QtGui.QStyledItemDelegate):
def _init_(self):
QtGui.QStyledItemDelegate._init_(self)
return
def paint(self, painter, option, index):
self.initStyleOption(option, index)
- Should return 4, per http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html#paint
- PySide returns 1, PyQt4 returns 4
print(option.version)
return
def sizeHint(self, option, index):
size = QtCore.QSize(option.rect.width(), option.fontMetrics.lineSpacing() * 5)
return size
if _name=="main_":
import sys
app = QtGui.QApplication(sys.argv)
model = QtGui.QStringListModel(["aaa", "bbb"])
item = TaskItemDelegate()
view = QtGui.QListView()
view.setModel(model)
view.setItemDelegate(item)
view.show()
app.exec_()
–