Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-115

QStyledItemDelegate.initStyleOption should modify option parameter to QStyleOptionViewItemV4 instead of QStyleOptionViewItem

    XMLWordPrintable

Details

    • Bug
    • Resolution: Cannot Reproduce
    • Not Evaluated
    • None
    • 1.2.x
    • PySide
    • 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)

      1. Should return 4, per http://qt-project.org/doc/qt-4.8/qstyleditemdelegate.html#paint
      2. 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_()

      Attachments

        1. style.py
          0.9 kB
        2. pyside-115-style.py
          0.9 kB

        Activity

          People

            Unassigned Unassigned
            codito Arun Mahapatra
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: