QTableWidget automatically sizes rows too large
-
@Publicnamer said in QTableWidget automatically sizes rows too large:
If a row has 1 word in it, the vertical space given to it is 1 line.
If a row has 2 words in it, the vertical space given to it is 2 lines.
If a row has 3 words in it, the vertical space given to it is 3 lines.
...I would try to diagnose this. If you (temporarily) set word wrap off, does that affect? More likely, can you (temporarily) switch off any column spanning, does that affect? And are you able to post a screen shot of what it looks like with, say, 3 rows of 1, 2 and 3 words respectively?
@JonB
Turning off word wrap has no effect.I decided to calculate my own row heights but this appears pointless too.
I tried changing the order in which I'm doing things e.g. setting the spans before/after the row heights, setting the text before/after setting the row heights.When I store correct row heights into the tablewidget with setRowHeight there is no effect. That's even when I do this:
verticalHeader->setSectionResizeMode(QHeaderView::Fixed);
It seems as though using spans causes some buggy code within qtablewidget to take over and it becomes unresponsive to a lot of calls.
-
@JoeCFD said in QTableWidget automatically sizes rows too large:
setMaximumSectionSize
OK I did that but it doesn't help. I need to have row heights that adapt to the contents. The contents may have different fonts, so they can't all be the same. I need the text to wrap.
@Publicnamer You can basically set the same font to each item. Then you will will not have any problem.
-
@Publicnamer You can basically set the same font to each item. Then you will will not have any problem.
@JoeCFD said in QTableWidget automatically sizes rows too large:
You can basically set the same font to each item
I'm already doing that. I tried just now not setting the font and the bug persists i.e. each Space character in my strings is treated as a Newline, so a four-word string causes a row height equivalent to 4 lines. And yet the Space characters do not cause line breaks when the strings are drawn.
-
@JoeCFD said in QTableWidget automatically sizes rows too large:
setMaximumSectionSize
this is what I did in my code.
m_tableWidget->verticalHeader()->setSectionResizeMode( QHeaderView::Fixed );
m_tableWidget->verticalHeader()->setMinimumSectionSize( item_height );
m_tableWidget->verticalHeader()->setMaximumSectionSize( item_height );
m_tableWidget->verticalHeader()->setDefaultSectionSize( item_height ); -
@JoeCFD said in QTableWidget automatically sizes rows too large:
setMaximumSectionSize
this is what I did in my code.
m_tableWidget->verticalHeader()->setSectionResizeMode( QHeaderView::Fixed );
m_tableWidget->verticalHeader()->setMinimumSectionSize( item_height );
m_tableWidget->verticalHeader()->setMaximumSectionSize( item_height );
m_tableWidget->verticalHeader()->setDefaultSectionSize( item_height );@JoeCFD OK but each of my rows can be a different height, so that doesn't help me.
-
@JoeCFD OK but each of my rows can be a different height, so that doesn't help me.
@Publicnamer
try this
m_tableWidget->verticalHeader()-> resizeSection(int logicalIndex, int size) -
@Publicnamer
try this
m_tableWidget->verticalHeader()-> resizeSection(int logicalIndex, int size)@JoeCFD said in QTableWidget automatically sizes rows too large:
m_tableWidget->verticalHeader()-> resizeSection(int logicalIndex, int size)
I tried replacing setRowHeight with that but it doesn't work either :
verticalHeader->resizeSection(myRow, myRowHeight);
AFAIK I'm only dealing with rows, not sections.
-
@JoeCFD said in QTableWidget automatically sizes rows too large:
m_tableWidget->verticalHeader()-> resizeSection(int logicalIndex, int size)
I tried replacing setRowHeight with that but it doesn't work either :
verticalHeader->resizeSection(myRow, myRowHeight);
AFAIK I'm only dealing with rows, not sections.
@Publicnamer
horizontal header section defines column width.
vertical header section defines row height. -
@Publicnamer
horizontal header section defines column width.
vertical header section defines row height.@JoeCFD
OK what is a section in this context?Also, why would a call to table->setRowHeight(row, height) have no effect?
-
@JoeCFD
OK what is a section in this context?Also, why would a call to table->setRowHeight(row, height) have no effect?
@Publicnamer
OK I believe I found the bug.At the end of my function which fills the table with data, I had a call to:
void QTableView::resizeRowsToContents()
This was overriding all of my attempts to programmatically set the ideal row sizes but more importantly it was setting bogus row heights.