Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Setting QTableWidgetItem background color with QComboBox on mac
Forum Update on Monday, May 27th 2025

Setting QTableWidgetItem background color with QComboBox on mac

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 2 Posters 1.3k 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.
  • P Offline
    P Offline
    patrickkidd
    wrote on last edited by
    #1

    Hello!

    I am trying to set the background color of a QTableWidget item when QComboBox is set as the cell widget on mac (see attached screenshot). The other table items honor the palette's background color just fine, but this one does not. Help?

    def setBackground(w, c):
        p = QPalette(w.palette())
        w._orig_bg = p.color(QPalette.Window)
        w.setAutoFillBackground(True)
        p.setColor(QPalette.Window, c)
        w.setPalette(p)
    
    self.item(row, iDate).setBackground(bc)
    self.item(row, iDescription).setBackground(bc)
    self.item(row, iLogged).setBackground(bc)
    self.item(row, iPerson).setBackground(bc)
    

    0_1518806705121_2018-02-16_10-42-51.jpg

    https://alaskafamilysystems.com/

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

      Hi,

      The cell widget doesn't care about the cell underneath as it is not part of the cell. You may have to do some custom painting.

      However, do you really need that combo box shown permanently rather than as an editor when editing the cell content ?

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

      P 2 Replies Last reply
      0
      • SGaistS SGaist

        Hi,

        The cell widget doesn't care about the cell underneath as it is not part of the cell. You may have to do some custom painting.

        However, do you really need that combo box shown permanently rather than as an editor when editing the cell content ?

        P Offline
        P Offline
        patrickkidd
        wrote on last edited by
        #3

        @SGaist You know, I actually don't need it to be permanent and the table would probably perform better if I didn't show comboboxes. Thanks...

        https://alaskafamilysystems.com/

        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          The cell widget doesn't care about the cell underneath as it is not part of the cell. You may have to do some custom painting.

          However, do you really need that combo box shown permanently rather than as an editor when editing the cell content ?

          P Offline
          P Offline
          patrickkidd
          wrote on last edited by
          #4

          @SGaist said in Setting QTableWidgetItem background color with QComboBox on mac:

          Hi,

          The cell widget doesn't care about the cell underneath as it is not part of the cell. You may have to do some custom painting.

          Does that mean that the white is coming from the QComboBox or the cell widget? Seems like a QComboBox doesn't draw a background, at least in Creator?

          https://alaskafamilysystems.com/

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

            The combo box is the cell widget. IIRC, you can use a style sheet to change the background colour of your cell widget.

            But as you noted, you will indeed have a performance impact using cell widgets.

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

            P 1 Reply Last reply
            0
            • SGaistS SGaist

              The combo box is the cell widget. IIRC, you can use a style sheet to change the background colour of your cell widget.

              But as you noted, you will indeed have a performance impact using cell widgets.

              P Offline
              P Offline
              patrickkidd
              wrote on last edited by
              #6

              @SGaist said in Setting QTableWidgetItem background color with QComboBox on mac:

              The combo box is the cell widget. IIRC, you can use a style sheet to change the background colour of your cell widget.

              I guess I am not sure how to use a stylesheet to set the background color for the QComboBox on mac, as setting the "background" property via css overrides the entire mac style for the widget.

              I also noticed that the QListView correctly draws the background color for the selected row. It's just when I set QPalette.Window using QWidget::setPalette() and the row is unselected that it doesn't work (see attached screenshot). So this is possible, somehow.

              0_1518819579543_2018-02-16_14-17-37.jpg

              https://alaskafamilysystems.com/

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

                It's not the same properties that are used to render the selection rectangle and standard items. You'd likely have to dig a bit in Qt's internals to find out the differences. But again, using the combo box only as an editor is a better idea in terms of performance.

                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

                • Login

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