0

I have an issue usign QTableWidgetItem. I normally use the QTableWidget like this

    this->setItem(i, j, new QTableWidgetItem());
    this->item(i, j)->setText(string);

The column I'm writing to is narrow, only about 20px. I need to write 2 digits in there and from the definition I cannot resize the column.

The problem is that once the text overlaps the column width, it totally disappears and only three dots (or even nothing) appear instead. Can I suppress this behavior? I dont mind if there will be 1-2px overlap/clip, but I'm definitely not comfortable with the text disappearance.

Thanks for any help.

EDIT:

Well, after a couple of tries, I must say that the TextElide think works, however, now I face another problem. Sometimes, when there are more lines in the QTableWiddgetItem, the bottom lines just disappear and only the top one is visible. Any suggestions why this may happen?

EDIT 2:

It looks like this....note that the only difference between the images is a bigger font size. The cells are definitely high enough to containt all the text. http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug1.png http://www.stud.fit.vutbr.cz/~xnavra23/TWIbug2.png

Lord_Navro
  • 80
  • 1
  • 9

2 Answers2

0

Have you tried setting the sizeHint of the item? See this

snoofkin
  • 8,725
  • 14
  • 49
  • 86
0

See the textElideMode property. this->setTextElideMode(Qt::ElideNone) will remove the dots.

gwohpq9
  • 2,143
  • 2
  • 18
  • 18
  • Well, after a couple of tries, I must say that the TextElide think works, however, now I face another problem. Sometimes, when there are more lines in the QTableWiddgetItem, the bottom lines just disappear and only the top one is visible. Any suggestions why this happens? – Lord_Navro Apr 28 '11 at 09:47
  • This is size related. resizeRowToContents() should fix it but its quite slow. Otherwise, set the appropriate ResizeMode on the QHeaderView. – gwohpq9 Apr 28 '11 at 10:21
  • Hi, i do use it...my code is something like `for(cell in 1st row) cell.setText("1\n2\n3\n");this->resizeRowToContents(0);` The cells are high enough to containt all the lines of text (i even tried to colorize cellWidgetItem background to see if they match the grid), but for some reason in some cases some lines are omitted...ill try to post a screenshot somewhere – Lord_Navro Apr 28 '11 at 10:33
  • I don't know about that. Maybe its related to width, as it appears to only happen with two digit numbers. You should make a new thread about it. – gwohpq9 Apr 28 '11 at 11:15