Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. QTableView - CheckState
Forum Updated to NodeBB v4.3 + New Features

QTableView - CheckState

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 2 Posters 710 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • MasterQM Offline
    MasterQM Offline
    MasterQ
    wrote on last edited by
    #1

    HI,

    it's me, ... again ;-)

    I am using the feature CheckState in my QTableView. I see differences again between C++ version and Python version.

    While C++ is showing a hook 58cde200-b93a-4d0d-882e-7c5da1d33e80-grafik.png as checkmark, Python is using a filled rectangle 85edb2d6-9fd6-4c00-8f38-d26ceb54cd49-grafik.png .

    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 !!

    JonBJ 1 Reply Last reply
    0
    • MasterQM MasterQ

      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 fusion for both.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #4

      @MasterQ
      Screenshot 2024-11-27 162258.png

      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 to PartiallyChecked where your C++ sets it to Checked.... That's why we always need a minimal example with your code. If you are using 1, True or an expression returning true for Qt.CheckState.Checked that is wrong, and would set Qt.CheckState.PartiallyChecked.

      1 Reply Last reply
      1
      • MasterQM MasterQ

        HI,

        it's me, ... again ;-)

        I am using the feature CheckState in my QTableView. I see differences again between C++ version and Python version.

        While C++ is showing a hook 58cde200-b93a-4d0d-882e-7c5da1d33e80-grafik.png as checkmark, Python is using a filled rectangle 85edb2d6-9fd6-4c00-8f38-d26ceb54cd49-grafik.png .

        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 !!

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #2

        @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.

        1 Reply Last reply
        0
        • MasterQM Offline
          MasterQM Offline
          MasterQ
          wrote on last edited by
          #3

          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 fusion for both.

          JonBJ 1 Reply Last reply
          0
          • MasterQM MasterQ

            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 fusion for both.

            JonBJ Offline
            JonBJ Offline
            JonB
            wrote on last edited by JonB
            #4

            @MasterQ
            Screenshot 2024-11-27 162258.png

            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 to PartiallyChecked where your C++ sets it to Checked.... That's why we always need a minimal example with your code. If you are using 1, True or an expression returning true for Qt.CheckState.Checked that is wrong, and would set Qt.CheckState.PartiallyChecked.

            1 Reply Last reply
            1
            • MasterQM MasterQ has marked this topic as solved on
            • MasterQM Offline
              MasterQM Offline
              MasterQ
              wrote on last edited by
              #5

              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 for Qt.CheckState.Checked that is wrong, and would set Qt.CheckState.PartiallyChecked.

              That was the point.

              thnx

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved