I'm working on a QTableWidget
with some QLabel
inside it, but I need the QLabel to line-break automatically. I've tried setWordWrap
from this question:
QVBoxLayout *newL = new QVBoxLayout;
QTableWidget * tab = new QTableWidget; tab->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);
newL->addWidget(tab);
tab->setRowCount(1);
tab->setColumnCount(1);
QLabel *lb = new QLabel; lb->setText("testing");
lb->setWordWrap(true);
tab->setCellWidget(0,0,lb);
QWidget *window = new QWidget;
window->setLayout(newL);
window->show();
Problems
- If one word is really lengthy, the
wordWrap
doesn't move to a new line. Instead, it just expand into outer region:
lb->setText("testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttesttestawd");
- If there're multiple lines (more than 2), the
QTableWidget
doesn't create more lines, so the lower lines are not shown:
lb->setText("test\ntest\ntest\ntest\ntest\ntest");
- Even if there're only spaces between words, the
QTableWidget
still doesn't expand more than 2 lines:
lb->setText("test test test test test test test");
Questions
For the first problem, I'd like the text to switch to new line exactly at the point that the text go to outer region, even if there're no
\n
character.For the second and third problem, I'd like the
QWidgetTable
to provide enough space to show all the text.
Any suggestions?