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 Updated to NodeBB v4.3 + New Features

QTableView QHeaderView Sorted Column Style.

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.5k 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.
  • David.ReznicekD Offline
    David.ReznicekD Offline
    David.Reznicek
    wrote on 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.

    raven-worxR 1 Reply Last reply
    0
    • David.ReznicekD David.Reznicek

      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.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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

      David.ReznicekD 1 Reply Last reply
      1
      • David.ReznicekD Offline
        David.ReznicekD Offline
        David.Reznicek
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • raven-worxR raven-worx

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

          David.ReznicekD Offline
          David.ReznicekD Offline
          David.Reznicek
          wrote on 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

          • Login

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