QTableView - CheckState
-
HI,
it's me, ... again ;-)
I am using the feature
CheckState
in myQTableView
. I see differences again between C++ version and Python version.While C++ is showing a hook
as checkmark, Python is using a filled rectangle
.
As I would prefere a hook (it is to distinguish easier between checked and unchecked state in dark mode), I am wondering if it is possible to select programmically what is used. Can the
QCheckbox
behind that feature accessed/modified by own code in some way? .. without writing my own painter !! -
from PySide6.QtCore import Qt from PySide6 import QtWidgets, QtGui class MainWindow(QtWidgets.QTableView): def __init__(self): super().__init__() self.model = QtGui.QStandardItemModel(5, 5) self.setModel(self.model) item = QtGui.QStandardItem() item.setCheckable(True) item.setCheckState(Qt.CheckState.Unchecked) self.model.setItem(0, 0, item) item = QtGui.QStandardItem() item.setCheckable(True) item.setCheckState(Qt.CheckState.PartiallyChecked) self.model.setItem(0, 1, item) item = QtGui.QStandardItem() item.setCheckable(True) item.setCheckState(Qt.CheckState.Checked) self.model.setItem(0, 2, item) app = QtWidgets.QApplication([]) window = MainWindow() window.resize(400, 100) window.show() app.exec()
Ubuntu 22.04, PySide6.7.2.
Python is using a filled rectangle
If I didn't know better I would say your Python code is setting the
CheckState
toPartiallyChecked
where your C++ sets it toChecked
.... That's why we always need a minimal example with your code. If you are using1
,True
or an expression returning true forQt.CheckState.Checked
that is wrong, and would setQt.CheckState.PartiallyChecked
. -
@MasterQ
When you say "Python" please state PySide or PyQt and version. "Python" does nothing, it's down to which library/bindings you use. And platform for a question like this.Usually PySide/PyQt are really thin Python-bindings onto underlying Qt, so they don't do/change anything themselves. Checkmark might differ by style for app, are you using same style (e.g.
Fusion
)?Otherwise I guess it's possible the checkmark is an image/icon in Qt libraries and PySide/PyQt isn't able to find it, for unknown reason, though I'm thinking this is not the case.
-
from PySide6.QtCore import Qt from PySide6 import QtWidgets, QtGui class MainWindow(QtWidgets.QTableView): def __init__(self): super().__init__() self.model = QtGui.QStandardItemModel(5, 5) self.setModel(self.model) item = QtGui.QStandardItem() item.setCheckable(True) item.setCheckState(Qt.CheckState.Unchecked) self.model.setItem(0, 0, item) item = QtGui.QStandardItem() item.setCheckable(True) item.setCheckState(Qt.CheckState.PartiallyChecked) self.model.setItem(0, 1, item) item = QtGui.QStandardItem() item.setCheckable(True) item.setCheckState(Qt.CheckState.Checked) self.model.setItem(0, 2, item) app = QtWidgets.QApplication([]) window = MainWindow() window.resize(400, 100) window.show() app.exec()
Ubuntu 22.04, PySide6.7.2.
Python is using a filled rectangle
If I didn't know better I would say your Python code is setting the
CheckState
toPartiallyChecked
where your C++ sets it toChecked
.... That's why we always need a minimal example with your code. If you are using1
,True
or an expression returning true forQt.CheckState.Checked
that is wrong, and would setQt.CheckState.PartiallyChecked
. -
M MasterQ has marked this topic as solved on
-
Yes, you are right.
PartiallyChecked
is the right key word here.Now I see, what the difference was between my C++ version and the Python version.
@JonB said in QTableView - CheckState:
If you are using
1
,True
or an expression returning true forQt.CheckState.Checked
that is wrong, and would setQt.CheckState.PartiallyChecked
.That was the point.
thnx