user152508
user152508

Reputation: 3131

How to put new line in QTableWidgetItem

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.

Upvotes: 2

Views: 4076

Answers (1)

Meysam Hit
Meysam Hit

Reputation: 449

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.

Upvotes: 4

Related Questions