Python Forum
Displaying error in QTableview and with Checkbox in Column under macOsX
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Displaying error in QTableview and with Checkbox in Column under macOsX
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  [PyQt] PyQt5 QTableView SQLite : edit cell HeinKurz 2 2,286 Mar-27-2023, 10:41 AM
Last Post: HeinKurz
  [PyQt] choose checkbox devilonline 1 1,239 Feb-17-2023, 01:23 PM
Last Post: Axel_Erfurt
  [PyQt] QStyledItemDelegate and QTableView malonn 1 1,600 Feb-07-2023, 07:15 PM
Last Post: malonn
  [PyQt] QTableView set header labels HeinKurz 2 6,426 Jan-23-2023, 08:46 AM
Last Post: HeinKurz
  [PyQt] Determine whether text in QTableView cell is fully visible or not random_nick 0 957 Oct-27-2022, 09:29 PM
Last Post: random_nick
  [PyQt] QTableView: scroll to top cell of the screen random_nick 2 2,768 Oct-08-2022, 12:29 AM
Last Post: random_nick
  [PyQt] [Solved]Add a Blank Row To QTableView Extra 3 5,373 Oct-02-2022, 04:53 PM
Last Post: Extra
  [Tkinter] Dynamic checkbox treeview issue OogieM 8 4,820 Mar-20-2022, 02:10 PM
Last Post: OogieM
  How to update the list of a combo box in a QTableView panoss 10 6,132 Feb-05-2022, 03:24 PM
Last Post: panoss
  tkinter change the text of the checkbox zazas321 1 3,759 Sep-17-2021, 06:19 AM
Last Post: zazas321

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020