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. alignment for QCheckBox in QTableWidget
QtWS25 Last Chance

alignment for QCheckBox in QTableWidget

Scheduled Pinned Locked Moved Solved Qt for Python
pyside2qt for python
9 Posts 4 Posters 8.4k Views
  • 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.
  • C Offline
    C Offline
    cow_goes_meow
    wrote on last edited by cow_goes_meow
    #1

    I've created a checkbox in a cellwidget within a tablewidget. The checkbox is by default aligned left, like the image attached I can't find any documentation in QCheckBox to set alignment.

    Any help? Is there some sort of spacing or padding for qtablewidget?

    Thanks

    cow

    Capture.JPG

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      How did you create them ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • C Offline
        C Offline
        cow_goes_meow
        wrote on last edited by
        #3

        I think something reproducible would be:

        ccHeaders = QtWidgets.QTableWidget()
        checkbox = QtWidgets.QCheckBox()
        ccHeaders.setCellWidget(0, 0, checkbox)

        1 Reply Last reply
        0
        • C Offline
          C Offline
          cow_goes_meow
          wrote on last edited by
          #4

          @Denni-0 said in alignment for QCheckBox in QTableWidget:

          The alignment is not part of checkbox that is why you cannot find it -- the alignment feature is actually part of tablewidget and more precisely that column of your tablewidget

          I looked for alignment in qtablewidget also, and couldn't find anything: https://doc.qt.io/qtforpython/PySide2/QtWidgets/QTableWidget.html

          I know set alignment is in a tablewidgetitem, but this isn't considered an item, right?

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by SGaist
            #5

            Why not use the Qt.ItemIsUserCheckable flag to get the checkboxes you want rather than widgets San you are doing ?

            Widgets set like that will not respond to any role because they are not part of the rendering of the model.

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            C 1 Reply Last reply
            3
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by SGaist
              #6

              Nop, using setIndexWidget setCellWidget puts a widget on that cell but it does not care about the model content.

              The documentation clearly indicates that it should only be used on special cases for static content and not like done currently to show widgets on each and every line.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                You didn't (and it was setCellWidget, my bad) but the OP did.
                It comes from the original post

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • SGaistS SGaist

                  Why not use the Qt.ItemIsUserCheckable flag to get the checkboxes you want rather than widgets San you are doing ?

                  Widgets set like that will not respond to any role because they are not part of the rendering of the model.

                  C Offline
                  C Offline
                  cow_goes_meow
                  wrote on last edited by
                  #8

                  @SGaist said in alignment for QCheckBox in QTableWidget:

                  Why not use the Qt.ItemIsUserCheckable flag to get the checkboxes you want rather than widgets San you are doing ?

                  Widgets set like that will not respond to any role because they are not part of the rendering of the model.

                  I originally went with this and had issues with how I coded it, so I went with the checkbox route. But a clear head does wonders, and I did it this way. Thank you guys.

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    ChortleMortal
                    wrote on last edited by
                    #9

                    I know this topic is marked solved, but I can't figure out what anyone is saying the solution is. So to be helpful I suggest using setSyleSheet().

                    For example:
                    QCheckBox * cb = new QCheckBox("Show");
                    cb->setStyleSheet("padding-left: 10px;");
                    tileInfoTable->setCellWidget(TI_SHOW,col,cb);

                    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