-
Bug
-
Resolution: Out of scope
-
Not Evaluated
-
None
-
6.0.1, 6.1.2
-
None
-
macOS Big Sur & windows 10
PYTHON 3.9
from PySide6 import QtCore, QtGui, QtWidgets from PySide6.QtWidgets import * import sys from PySide6.QtCore import Qt data = [("1", "Baharak", 10), ("2", "Darwaz", 60), ("3", "Fays abad", 20), ("4", "Ishkashim", 80), ("5", "Jurm", 100)] class ProgressDelegate(QtWidgets.QStyledItemDelegate): def paint(self, painter, option, index): if index.column() == 2: progress = index.data(Qt.UserRole+1) print(type(progress)) opt = QtWidgets.QStyleOptionProgressBar() opt.state = QtWidgets.QStyle.State_Enabled opt.direction = QApplication.layoutDirection() opt.rect = option.rect opt.minimum = 0 opt.maximum = 100 opt.textAlignment = Qt.AlignCenter opt.progress = progress opt.text = "{}%".format(progress) opt.textVisible = True QApplication.style().drawControl(QStyle.CE_ProgressBar, opt, painter) if __name__ == '__main__': app = QtWidgets.QApplication(sys.argv) w = QtWidgets.QTableView() w.setColumnWidth(1, 250) w.setColumnWidth(2, 250) w.setFixedSize(500, 400) model = QtGui.QStandardItemModel() model.setHorizontalHeaderLabels(["ID", "Name", "Progress"]) r = 0 for _id, _name, _progress in data: it_id = QtGui.QStandardItem(_id) it_name = QtGui.QStandardItem(_name) it_progress = QtGui.QStandardItem(str(_progress)) it_progress.setData(_progress, Qt.UserRole+1) model.setItem(r, 0, QtGui.QStandardItem(it_id)) model.setItem(r, 1, QtGui.QStandardItem(it_name)) model.setItem(r, 2, QtGui.QStandardItem(it_progress)) r += 1 w.setModel(model) delegate = ProgressDelegate(w) w.setItemDelegateForColumn(2, delegate) # app.setStyle('Fusion') w.show() sys.exit(app.exec_())
FYI:
show correctly on pyqt5 with windows10
show correctly on pyqt5 with macOS Big Sur (only fushion style)
can not show correctly on pyside6 with neither window10 or macOS Big Sur
- relates to
-
QTBUG-91416 QStyle::subControlRect() gives incorrect result for slider handle
-
- Closed
-