Mar-17-2017, 03:06 PM
(This post was last modified: Mar-17-2017, 03:06 PM by nieselfriem.)
Hi,
I have the following problem.
I create a TableModel and a Delegate Class to display Boolean values in a column with Checkboxes.
You can see a screenshot with this link
Thanks and greetings
niesel
I have the following problem.
I create a TableModel and a Delegate Class to display Boolean values in a column with Checkboxes.
# coding=utf-8 from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * class CheckBoxDelegate(QItemDelegate): def __init__(self, parent=None): QItemDelegate.__init__(self, parent) self.chkboxSize = 19 # ?! def createEditor(self, parent, option, index): chkbox = QCheckBox(parent) chkbox.setText('') chkbox.setTristate(False) left = option.rect.x() + (option.rect.width() - self.chkboxSize) / 2 top = option.rect.y() + (option.rect.height() - self.chkboxSize) / 2 chkbox.setGeometry(left, top, self.chkboxSize, self.chkboxSize) return chkbox def paint(self, painter, option, index): value = index.data() opt = QStyleOptionButton() opt.state |= QStyle.State_Enabled | (QStyle.State_On if value else QStyle.State_Off) opt.text = '' left = option.rect.x() + (option.rect.width() - self.chkboxSize) / 2 top = option.rect.y() + (option.rect.height() - self.chkboxSize) / 2 opt.rect = QRect(left, top, self.chkboxSize, self.chkboxSize) QApplication.style().drawControl(QStyle.CE_CheckBox, opt, painter) def updateEditorGeometry(self, editor, option, index): passNow the link to my Tableview:
self.dataTBL.setItemDelegateForColumn(2, CheckBoxDelegate(self.dataTBL))It works fine on Windows and Linux. But I have a displaying error on macOsX. The checkbox is not displaying in column 3 but the checkbox is displaying and overlapping in the first column. How I can fix this?
You can see a screenshot with this link
- Windows: https://www.dropbox.com/s/ptfvfwo73oo21i...4.png?dl=0
- Linux: https://www.dropbox.com/s/c1ci3l89fp4v4q...p.png?dl=0
- and macOs: https://www.dropbox.com/s/z9vm6qybnajx4u...1.png?dl=0
Thanks and greetings
niesel