Checkbox wird in tabelle unter MacosX falsch dargestellt
Verfasst: Freitag 17. März 2017, 08:42
Hallo,
ich habe folgendes Problem.
Ich habe in einem Tabellenmodell mir für die Darstellung von Booleanwerte eine Checkbox als delegate eingerichtet.
[codebox=python file=Unbenannt.txt]
# 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):
pass
[/code]
diese habe ich dann wie folgt eingebunden
Das funktioniert auch auf Windows und unter Linux so weit ganz gut. Nur unter MacOSX gibt es Darstellungsfehler. Die Checkbox wird nicht mehr in der Spalte 3 dargestellt sondern überdeckt das Datum der 1. Spalte. (siehe Screenshots) Was kann ich machen, dass es solche Darstellungsfehler vermeiden kann und wie behebe ich diesen?
Linux: https://www.dropbox.com/s/c1ci3l89fp4v4 ... p.png?dl=0
MacOs: https://www.dropbox.com/s/z9vm6qybnajx4 ... 1.png?dl=0
Windows: https://www.dropbox.com/s/ptfvfwo73oo21 ... 4.png?dl=0
VG niesel
ich habe folgendes Problem.
Ich habe in einem Tabellenmodell mir für die Darstellung von Booleanwerte eine Checkbox als delegate eingerichtet.
[codebox=python file=Unbenannt.txt]
# 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):
pass
[/code]
diese habe ich dann wie folgt eingebunden
Code: Alles auswählen
self.dataTBL.setItemDelegateForColumn(2, CheckBoxDelegate(self.dataTBL))
Linux: https://www.dropbox.com/s/c1ci3l89fp4v4 ... p.png?dl=0
MacOs: https://www.dropbox.com/s/z9vm6qybnajx4 ... 1.png?dl=0
Windows: https://www.dropbox.com/s/ptfvfwo73oo21 ... 4.png?dl=0
VG niesel