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) sort indicator alignment

QTableView (QHeaderView) sort indicator alignment

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 647 Views 2 Watching
  • 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.
  • R Offline
    R Offline
    rTommy
    wrote on last edited by
    #1

    The sort indicator within a QHeaderView (of a QTableView) has a default alignment.
    In case of QCommonStyle (default) it is Qt::AligRight | Qt::AlignVCenter. It is visible when the header has multiple lines. For example:

    Example

    What is the simplest/easiest way to change that alignment to Qt::AlignRight | Qt::AlignTop?

    I was unable to locate it in the source code hence, don't know what to customize.

    Additionally, it seems there is a marging/padding/spacing issue too. You can see that the Column text "Column" is kind of cropped and the last character is not fully shown.

    I have no idea why that happens.

    horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeToContents) is already set.

    Qt version is 6.8.1.

    Thank you!

    1 Reply Last reply
    0
    • R Offline
      R Offline
      rTommy
      wrote on last edited by rTommy
      #2

      I tried experimenting with styleSheet but I assume I would need to add more into the stylesheet beside what I had so far?

      QHeaderView::down-arrow { margin: 10; width: 14; height: 8; position: static; subcontrol-position: right top; subcontrol-origin: content;}
      QHeaderView::up-arrow { margin: 10; width: 14; height: 8; position: static; subcontrol-position: right top; subcontrol-origin: content;}

      example

      Problems here:

      • the last character cropping issue is still there
      • the column width got bigger and can't explain why
      • the width: 14 and height: 8 are based on the source code but I cannot identify why margin: 10 is required to achieve the same as the default

      qfusionstyle.cpp:
      qt_fusion_draw_arrow()

      But that function only produces the triangle down/up arrow...

          const qreal dpi = QStyleHelper::dpi(option);                   // = 96
          const qreal dpr = painter->device()->devicePixelRatio();       // = 2
          const int arrowWidth = int(QStyleHelper::dpiScaled(14, dpi));  // = 14
          const int arrowHeight = int(QStyleHelper::dpiScaled(8, dpi));  // = 8
      
          const int arrowMax = qMin(arrowHeight, arrowWidth);            // = 8
          const int rectMax = qMin(rect.height(), rect.width());         // = 24, rect: w24 x h39 (in my case)
          const int size = qMin(arrowMax, rectMax);                      // = 8
      ...
              QRectF arrowRect;
              arrowRect.setWidth(size);                                  // = 8
              arrowRect.setHeight(arrowHeight * size / arrowWidth);      // = 4
      

      Thanks!

      1 Reply Last reply
      0
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by SGaist
        #3

        Hi and welcome to devnet,

        You wouldn't happen to be on Windows ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rTommy
          wrote on last edited by
          #4

          Yes, this is Windows 11 but with dark theme (which is "fusion", the common style).

          With the default light Windows theme the indicator is on Top&HCenter, in that case my issue is not valid.

          1 Reply Last reply
          0
          • R rTommy referenced this topic on
          • P Offline
            P Offline
            p.gs
            wrote on last edited by
            #5

            I also found a croppig problem each time a headerview style for an up-arrow or down-arrow has been set, it doesn't matter whether the style definition contains any attributes or not.
            Effect can be reproduced even by:

            QHeaderView::down-arrow { }
            

            Seems to be a bug in my eyes.

            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