Python Forum

Full Version: Displaying error in QTableview and with Checkbox in Column under macOsX
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

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):
        pass
Now 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

Thanks and greetings

niesel
If you print the option values, are they all zeros for mac?

I'm just guessing, but maybe it's trying to draw earlier than it should, so position values don't have values yet. If that's the case, you should probably file a bug report with pyqt... it shouldn't do different things on different platforms.