0

I use a subclassed QTableWidget with QTableWidgetItems in cells to display certain data. In the first row, I have a set of numbers separated by new lines in each cell. My problem is that when I increase font size/decrease cell size, some lines completely disappear, allthough the cell is definitely high enough to contain them.

This usually appears when there is a 2-digit number with some other lines under it and (probably) the font size is greater than the box width can match. I have the elide mode set to none to suppress the "three dots" that appear when this happens.

this->setTextElideMode(Qt::ElideNone);

The first row is resized by

this->resizeRowToContents(0); this->setRowWidth(0, this->rowWidth(0) + 10);

so that its high enough.

However, the numbers keep on disappearing. Example shown here, note the font size change and missing numbers.

http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug1.png

http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug2.png

I'm starting to be quite desparate about this...any help highly appreciated.

Lord_Navro
  • 80
  • 1
  • 9

2 Answers2

0

Just to investigate the problem, try:

  1. Make shure that string is correctly created (2,5,10,3) and not (10,3)
  2. Try letters instead of numbers to make shure that they are shown
  3. Try use 3digits nuber alongside with 2digits and see what is happened
  4. May be workaround this by using 01,02 numbers?
Sergey Leyko
  • 369
  • 6
  • 14
  • Hi, 1. it definitely gets created correctly, the font-size changing function has nothing to do with the contents (debugged). 2. I use QString::number, QStringList::join and then .setText to change the contents of the cells, i'm sure its ok. 3. the problem is still the same, when 1 line exceeds cell width, other lines are omitted. 4. this makes the problem even worse (lines under 2-digit numbers exceeding the width disappead). Thanks for suggestion, though – Lord_Navro Apr 28 '11 at 13:52
0

Try resizeColumnsToContents() instead of setColumnWidth. If that doesn't work, try calling resizeColumnsToContents() before resizeRowToContents(0).
By the way, is there any reason for calling resizeRowToContents(0) instead of resizeRowsToContents() (note the different name)?

TonyK
  • 16,761
  • 4
  • 37
  • 72
  • Hi, sorry for the mix-up, I treat both the first row and first column this way - `this->resizeColumnToContents(0);this->resizeRowToContents(0);this->setColumnWidth(0, this->columnWidth(0) + 10);this->setRowHeight(0, this->rowHeight(0) + 10);` But only the first row makes the problems, becouse in the first column cells there are no multi-line texts. As I mentioned before, the height of the cellwidget is no problem, it is definitely ok. I think its the way the QTableWidgetItem treats the text that makes the issue. – Lord_Navro Apr 28 '11 at 14:24
  • I said `resizeColumnsToContents`, not `resizeColumnToContents`. Try it. – TonyK Apr 28 '11 at 15:07
  • Thats not possible, i need the other colunms to have an exact width...this was my previous question http://stackoverflow.com/questions/5781589/qtablewidgetitem-shrinking/5791690#5791690 – Lord_Navro Apr 28 '11 at 17:11
  • @Lord_Navro: It looks like you have vertical alignment set to Qt::AlignBottom. Is that right? This looks like a bug in Qt (which is perhaps more likely for such a rare option). Try this: set vertical alignment to Align::Top, and add enough newline characters at the beginning so that all columns have the same number of rows. What happens? – TonyK Apr 28 '11 at 20:03
  • @TonyK: It definitely does...I'll try QtCentre and will share the solution (if there is any), thanks for help though – Lord_Navro Apr 28 '11 at 23:44
  • @Lord: But what happens if you try out my `Align::Top` suggestion? – TonyK Apr 30 '11 at 08:01