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

QStyleOptionProgressBar Delegate displayed incorrectly in QTableView on MacOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Incomplete
    • Not Evaluated
    • None
    • 5.15.2, 6.0.0
    • PySide
    • None
    • macOS

    Description

      Implementation of the following sample code from QAbstractItemDelegate documentation displays broken layout on macOS (verified on Big Sur and Catalina), while the same code on Linux works as expected.

       

      import sys
      import os
      from PySide2.QtWidgets import (
       QApplication,
       QMainWindow,
       QTableView,
       QVBoxLayout,
       QWidget,
       QStyleOptionProgressBar,
       QStyledItemDelegate,
       QStyle
      )
      from PySide2.QtCore import QAbstractTableModel, QModelIndex, QSortFilterProxyModel
      from PySide2.QtGui import Qt
      data = [
       ['123', '456', '789'],
       ['456', '123', '789'],
       ['789', '789', '123'],
      ]
      class WidgetDelegate(QStyledItemDelegate):
       def __init__(self):
       super(WidgetDelegate, self).__init__()
      def paint(self, painter, option, index):
       if index.column() == 2:
       progress = 50
       self.progressBarOption = QStyleOptionProgressBar()
       self.progressBarOption.rect = option.rect
       self.progressBarOption.minimum = 0
       self.progressBarOption.minimum = 100
       QApplication.style().drawControl(QStyle.CE_ProgressBar, self.progressBarOption, painter)
       
       else:
       QStyledItemDelegate.paint(self, painter, option, index)
      
      class TableModel(QAbstractTableModel):
       headerLabels = ['Header1', 'Header2', 'Header3']
       def __init__(self, input_data = None):
       super(TableModel, self).__init__()
       self.tableData = input_data
       if self.tableData is None:
       self.tableData = list()
      def rowCount(self, parent = QModelIndex):
       try:
       row_count = len(self.tableData)
       return row_count
       except:
       return 0
      def columnCount(self, parent = QModelIndex):
       try:
       column_count = len(self.tableData[0])
       return column_count
       except:
       return 0
      def headerData(self, section, orientation, role=Qt.DisplayRole):
       if role == Qt.DisplayRole and orientation == Qt.Horizontal:
       return self.headerLabels[section]
      return QAbstractTableModel.headerData(self, section, orientation, role)
      def data(self, index, role = Qt.DisplayRole):
       if role == Qt.DisplayRole or role == Qt.EditRole:
       return self.tableData[index.row()][index.column()]
      class TableView(QTableView):
       def __init__(self):
       super(TableView, self).__init__()
       self.setSelectionBehavior(self.SelectRows)
      
      class MainWindow(QMainWindow):
       
       def __init__(self):
       super(MainWindow, self).__init__()
       self.tableView = TableView()
       self.delegate = WidgetDelegate()
       self.tableView.setItemDelegate(self.delegate)
       self.initUi()
       self.tableModel = TableModel(data)
       self.tableView.setModel(self.tableModel)
      
       def initUi(self):
       #----- Init UI -----
       mainLayout = QVBoxLayout()
       mainLayout.addWidget(self.tableView)
       mainWidget = QWidget()
       mainWidget.setLayout(mainLayout)
       self.setCentralWidget(mainWidget)
       self.resize(650, 350)
      if __name__ == "__main__":
       app = QApplication(sys.argv)
       window = MainWindow()
       window.show()
       sys.exit(app.exec_())
      

       

       

       

      Screenshot of the code execution:

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            nastya_medvedeva nastya_medvedeva
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes