2

I am having trouble to put new line in QTableWidgetItem. Here is the code :

QTableWidget* item = new QTableWidgetItem;
item->setText("Line1 \n Line2");

With this code the item text is not displayed in two lines, i.e it seems that \n character is ignored.

I have a workaround to do this, with using QPlainTextEdit and the function setCellWidget, in that case everything work as expected but is more ugly, and I prefer not to make additional widget just to show text in multiple lines.

user152508
  • 3,053
  • 8
  • 38
  • 58
  • http://stackoverflow.com/questions/5359017/qtablewidget-putting-multiple-lines-of-text-in-one-row – Zaiborg Apr 15 '13 at 12:44
  • what does not work? the code you show or the accepted answer in the link?? – UmNyobe Apr 15 '13 at 12:53
  • sorry the code that I showed doesn't work. I guess I will have to use QLineEdit to show multi line text just like in the provided link – user152508 Apr 15 '13 at 12:54

1 Answers1

4

I think your code is fine to separate lines. But you should change the size of each row to show multi-lines.

enter image description here

And after resizing row's height:

enter image description here

You see it's OK.

Meysam Hit
  • 439
  • 1
  • 4
  • 13