Alignment issue with QTableView text
-
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:
So I'm wondering, where does QTableView get its reference sizing for the text alignment from? Or, is there some other issue here?
-
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 ? -
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.