QTableView - CheckState
-
HI,
it's me, ... again ;-)
I am using the feature
CheckStatein 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
QCheckboxbehind that feature accessed/modified by own code in some way? .. without writing my own painter !! -
it is PySide6 (6.8.0.2).
I do not use own settings for Style so far. Both apps, C++ and PySide are running on the same machine under same conditions and taking such settings from the underlying KDE or using default ones.
It is
fusionfor both.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
CheckStatetoPartiallyCheckedwhere your C++ sets it toChecked.... That's why we always need a minimal example with your code. If you are using1,Trueor an expression returning true forQt.CheckState.Checkedthat is wrong, and would setQt.CheckState.PartiallyChecked. -
HI,
it's me, ... again ;-)
I am using the feature
CheckStatein 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
QCheckboxbehind that feature accessed/modified by own code in some way? .. without writing my own painter !!@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.
-
it is PySide6 (6.8.0.2).
I do not use own settings for Style so far. Both apps, C++ and PySide are running on the same machine under same conditions and taking such settings from the underlying KDE or using default ones.
It is
fusionfor both.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
CheckStatetoPartiallyCheckedwhere your C++ sets it toChecked.... That's why we always need a minimal example with your code. If you are using1,Trueor an expression returning true forQt.CheckState.Checkedthat is wrong, and would setQt.CheckState.PartiallyChecked. -
M MasterQ has marked this topic as solved on
-
Yes, you are right.
PartiallyCheckedis 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,Trueor an expression returning true forQt.CheckState.Checkedthat is wrong, and would setQt.CheckState.PartiallyChecked.That was the point.
thnx
