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

QTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 752 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.
  • G Offline
    G Offline
    GrahamLa
    wrote on last edited by
    #1

    Hi
    I am working with some legacy code that has a QTableWidget.
    My problem is that when displayed it looks like -
    0_1544020789285_6c65658b-2334-4215-9877-7d37973ee640-image.png
    Why is there a white block in the top left?

    Thanks

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      See http://doc.qt.io/qt-5/stylesheet-examples.html#customizing-qtableview

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      3
      • M Offline
        M Offline
        mdkb
        wrote on last edited by
        #3

        This remains unsolved and I ran into this same issue in 2025 with pyside6 and so far nothing has resolved it. I am implementing a dark mode in my python 3.12 application and getting an annoying white box in the top corner of the displayed database table. I was able to target it with a workaround while I kept styling inline but once I migrated to using dark.qss as an external stylesheet to homogonise my application styling it became unfixable and so far I have been unable to target it to change its color.

        The red circle below is not needed but I was discussing it with LLM and precision was required.

        shot-table-color-issue-cropped.png

        I'll go through the link from Vronin to see if I can find new approaches to solving this. If anyone has a solution please share else I will bring whatever I discover back and post it here once I find a workaround, or if I don't.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mdkb
          wrote on last edited by
          #4

          Well thanks @VRonin as it provided the solution that was unsolvable before. Here is a summary of my problem and how this solved it for the record.

          When using a dark stylesheet (dark.qss) the top-left corner button remains untargettable with styling. Calling findChild(QAbstractButton) and forcing a stylesheet in code helped for a moment, but the white square came back on resize, theme change, or first show.

          Root cause seemed to be Qt treats that corner button as part of the table header, not as a normal button. Header pieces are styled with the selector QHeaderView::section. The corner is a special header piece called QTableCornerButton::section. If you never tell Qt what colour that piece should be, it falls back to the system’s light colour even in dark mode which seems to be white.

          After hacking workarounds in the code and doing all sorts, I was still unable to resolve it permanently until approaching it treating the top-left select-all button as a header, not a button. Styling it with QTableWidget QTableCornerButton::section in my QSS and that was pretty much it. In my case adding this into my dark.qss theme file:

          /* Dark-theme top-left corner (select-all button) */
          QTableWidget QTableCornerButton::section {
              background-color: #2b2b2b;      /* same as table background */
              border: 1px solid #555555;      /* same as table border */
              border-bottom: 2px solid #777777;   /* optional – matches header underline */
          }
          

          also adding into the python script:

          app.setStyle("Fusion")

          and loading the stylesheet after the style is set.

          a simple example as a test was:

          import sys
          from PySide6.QtWidgets import QApplication, QTableWidget
          from pathlib import Path
          
          app = QApplication(sys.argv)
          app.setStyle("Fusion")
          
          # ---- dark.qss (only the relevant part) ----
          qss = """
          QTableWidget { background-color: #2b2b2b; color: #e0e0e0; }
          QHeaderView::section { background-color: #2b2b2b; color: #e0e0e0; border: 1px solid #555555; }
          QTableWidget QTableCornerButton::section {
              background-color: #2b2b2b;
              border: 1px solid #555555;
              border-bottom: 2px solid #777777;
          }
          """
          app.setStyleSheet(qss)
          
          w = QTableWidget(5, 3)
          w.show()
          app.exec()
          

          I hope that helps anyone running into this problem which clearly still exists in 2025 and until I found the info in the link shared by Vronin I was struggling to solve.

          1 Reply Last reply
          1

          • Login

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