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. Alignment issue with QTableView text
QtWS25 Last Chance

Alignment issue with QTableView text

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

    I have a QTableView with 3 columns, where I'm manually resizing the columns so that they always take equal amounts of space. I haven't modified any of the text alignments for the columns, but I'm having an issue with the right-most column's text alignment, where strings longer than 3 characters aren't aligned properly:

    0_1546899131158_right_column.png

    So I'm wondering, where does QTableView get its reference sizing for the text alignment from? Or, is there some other issue here?

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

      Hi,

      What version of Qt are you using ?
      On what platform ?
      How are you generating these data ?
      Can you provide a minimal compilable example that shows that behaviour ?

      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
      • Q Offline
        Q Offline
        Qt_User72653
        wrote on last edited by
        #3

        Qt 5.11.2 on Windows. The data comes from a custom variant type.

        I can't really make a minimal example, unless I strip out my custom types. If I can't figure it out soon I'll try to make an example that duplicates the issue.

        I did notice that if I set all column's TextAlignmentRole to Qt::AlignRight that the text of the second and third columns disappears off the right side of the column when the table is expanded horizontally, which leads me to believe that there's a discrepancy between the size that's actually visible, and the size that's being used to render/position the text.

        In the table's resizeEvent() method I have:

          setColumnWidth(0, width() / 3);
          setColumnWidth(1, width() / 3);
          setColumnWidth(2, width() / 3);
        

        Which is the only thing I can think of that would be affecting this.

        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