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. QTableView QHeaderView Sorted Column Style.
Forum Update on Tuesday, May 27th 2025

QTableView QHeaderView Sorted Column Style.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.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.
  • D Offline
    D Offline
    David.Reznicek
    wrote on 23 Jun 2016, 09:40 last edited by
    #1

    Hello,

    I would like to change text color in header if column is sorted. I try to use style:

    QHeaderView::section:checked{color: red;}

    QTableView settings:

    table->setSortingEnabled(true);

    Exists any easy way ho to set this text color via stylesheet?

    Thanks, David.

    R 1 Reply Last reply 24 Jun 2016, 09:58
    0
    • D David.Reznicek
      23 Jun 2016, 09:40

      Hello,

      I would like to change text color in header if column is sorted. I try to use style:

      QHeaderView::section:checked{color: red;}

      QTableView settings:

      table->setSortingEnabled(true);

      Exists any easy way ho to set this text color via stylesheet?

      Thanks, David.

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 24 Jun 2016, 09:58 last edited by
      #2

      @David.Reznicek
      I think this is not possible using stylesheets.

      But you should be able to achieve what you want in your model.
      By reimplementing headerData() and for the Qt::ForegroundRole return your desired QColor if the section is sorted. Otherwise return the result from the base class implementation.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      D 1 Reply Last reply 24 Jun 2016, 11:03
      1
      • D Offline
        D Offline
        David.Reznicek
        wrote on 24 Jun 2016, 10:15 last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • R raven-worx
          24 Jun 2016, 09:58

          @David.Reznicek
          I think this is not possible using stylesheets.

          But you should be able to achieve what you want in your model.
          By reimplementing headerData() and for the Qt::ForegroundRole return your desired QColor if the section is sorted. Otherwise return the result from the base class implementation.

          D Offline
          D Offline
          David.Reznicek
          wrote on 24 Jun 2016, 11:03 last edited by
          #4

          @raven-worx Thanks a alot....it works. Better than my workaround to override paintSection in QHeaderView.

          1 Reply Last reply
          0

          1/4

          23 Jun 2016, 09:40

          • Login

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