How to style a table in QTextEdit
-
Hi,
I think you are mixing two very different things here:
- Qt Style Sheet for customizing widgets
- QTextDocument Rich Text support shown through QTextEdit.
What you want to do is handled by the later. See the Rich Text chapter in Qt's documentation.
@SGaist Hello,
So, I got the border collapse working by doing this:TextEdit *edit{getTabTextEdit()}; QTextTableFormat format; format.setBorderCollapse(true); edit->textCursor().insertTable(lineNum, columnNum, format);
But I don't know how to set the table's width to change when the textedit's width changes and I don't know how to put its width to 100% as CSS does.
-
If memory serves well, something like:
format.setWidth(QTextLength(QTextLength::PercentageLength, 100));
-
If memory serves well, something like:
format.setWidth(QTextLength(QTextLength::PercentageLength, 100));
@SGaist Yes! This was right!
Thank you so much, but I have one last question, sorry about that.
When I create the table it's like this:
but then when I type something in a cell the line separing the different cells adapts to the text. How do I avoid that?
I just wanted to expand the table to the TextEdit's width not also this feature. -
So you want the column to all take the same percentage of space ?
-
Then QTextTableFormat::setColumnWidthConstraints looks like what you want.
-
Then QTextTableFormat::setColumnWidthConstraints looks like what you want.
@SGaist And how do I do that? I tried to search online but I didn't find any solution that may help me, because they are reguarding QTableView.
I also checked the documentation but it doesn't explain much and I still don't know how to use it.
Thanks in advance. -
QTextLength oneThird = QTextLength(QTextLength::PercentageLength, 33); QVector<QTextLength> constraints(3, oneThird); format.setColumnWidthConstraints(constraints);
-
QTextLength oneThird = QTextLength(QTextLength::PercentageLength, 33); QVector<QTextLength> constraints(3, oneThird); format.setColumnWidthConstraints(constraints);