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 section moved - styling
Forum Update on Monday, May 27th 2025

QTableView QHeaderView section moved - styling

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 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 style "moving section" in QTableView when columns order is changed? Please exist some easy way?

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

    Thanks. David.

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

      Hello,

      I would like to change style "moving section" in QTableView when columns order is changed? Please exist some easy way?

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

      Thanks. David.

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @David.Reznicek
      this is not possible.
      There may be only ways to change all tabs during the drag, but not the dragged one.

      --- 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 VRoninV 2 Replies Last reply
      0
      • raven-worxR raven-worx

        @David.Reznicek
        this is not possible.
        There may be only ways to change all tabs during the drag, but not the dragged one.

        David.ReznicekD Offline
        David.ReznicekD Offline
        David.Reznicek
        wrote on last edited by
        #3

        @raven-worx Thank you for response.

        1 Reply Last reply
        0
        • raven-worxR raven-worx

          @David.Reznicek
          this is not possible.
          There may be only ways to change all tabs during the drag, but not the dragged one.

          VRoninV Offline
          VRoninV Offline
          VRonin
          wrote on last edited by
          #4

          @raven-worx said:

          this is not possible.

          Everything is possible!

          you just need to create your own headerview reimplementing the paint event

          "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

          raven-worxR 1 Reply Last reply
          0
          • VRoninV VRonin

            @raven-worx said:

            this is not possible.

            Everything is possible!

            you just need to create your own headerview reimplementing the paint event

            raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by raven-worx
            #5

            @VRonin said:

            Everything is possible!

            you just need to create your own headerview reimplementing the paint event

            Of course everybody can download the Qt source code and modify it to his needs...

            I am very interested in your suggestion how to implement your paint() method implementation.
            I am pretty sure that the paint() method is simply not enough. And that most of the stuff happens in the private part of the class.

            Edit:

            checked the Qt sources. The dragged section is painted to a pixmap, which is then set to a label and this label, which is moved during the drag.
            The section is painted using paintSection(). So you can just change what the style option offers. And even this is not guaranteed and may be overwritten/ignored internally by the QStyle during drawing the control.
            So you you can copy as much of the code from paintSection() implementation and add a member to the paintEvent handler.
            The paintSection() should be called (may be more often than i found) only twice. Once in the paintEvent() handler and once for the dragging.
            So you you can copy as much of the code from paintSection() implementation as possible and add a member to the paintEvent handler to be able to distinguish from where you get called.

            void MyHeaderView::paintEvent(QPaintEvent* event)
            {
                 callFromPaintEvent = true;
                 QHeaderView::paintEvent(event);
                 callFromPaintEvent = false;
            }
            
            void MyHeaderView::paintSection(QPainter *painter, const QRect &rect, int logicalIndex) const
            {
                  if( callFromPaintEvent  )
                       return QHeaderView::paintSection( painter, rect, logicalIndex );
            
                  // do the painting for the dragged section
            }
            

            This solution is far beyond being ideal and also it's not very reliable (due to QStyle drawing).

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

            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