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. Custom QTableView Stylesheet
QtWS25 Last Chance

Custom QTableView Stylesheet

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 990 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.
  • K Offline
    K Offline
    kmbar2013
    wrote on last edited by
    #1

    I am using Qt 5.15. My application allows the user to switch between 3 different themes (none, dark, and light). When switching between themes one of my custom QTableViews stops using the selected stylesheet. This only happens when switching; upon application startup, it retains the proper last used theme's stylesheet. Other QTreeViews and/or QTableViews used in the application do not have this issue.

    Sample stylesheet contains:

    QAbstractItemView {
        background-color: #414147;
        alternate-background-color: #545459;
    }
    

    Even explicitly using:

    CustomTableView {
        background-color: #414147;
        alternate-background-color: #545459;
    }
    

    will still resort to the same odd behavior. Any suggestions on what I can look for to determine why the custom QTableView doesn't behave like the others?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Two things. First check if QEvent::StyleChange is sent to your custom widget. Second see if it works when you explicitly call qApp->polish(customWidgetPtr) after you set the new app style.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • K Offline
        K Offline
        kmbar2013
        wrote on last edited by kmbar2013
        #3

        Thanks for the info.

        There are times when QEvent::StyleChange was not received and of course the stylesheet was not correctly applied. But there were also times when it was received but the custom table view still ignored the stylesheet. (I printed the stylesheet each time the event was received.)
        I wasn't sure where I was supposed to make the polish call so I didn't get any additional information from this.

        Sometimes it's the rows that are not following the stylesheet and sometime it's the header that is not following the stylesheet. It is not consistent.

        Here's the table when there's no stylesheet selected.
        8950b105-0857-45a2-82cb-81528cac28c8-image.png

        Here the table ignored the background color and text color of the row it should be black with white text but the header section is correct.
        b3555f3f-588b-496a-8491-6a4b233d5b65-image.png

        Here the table ignored the background color of the row (it should be yellow) and the header section is correct.
        e7a9f70c-2eb3-44d6-adcc-1688a8043cc5-image.png

        Here the background color and text color of the row are correct but the header section is incorrect, the header section should be black with white text.
        9904df6c-3ed5-46ec-8a10-e70e1cf8351e-image.png

        Here the background color and text color of the row are correct but the header section is incorrect, the header section should be yellow with black text.
        3f258c0a-30dd-4e9c-82b9-e4d6971e2d1f-image.png

        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