QTextTable Topic
-
Hi all, looking forward to your support!
Here is some code, that creates a table:
QTextDocument* td =ui->te->document(); td->clear(); QTextCursor tc(td); tc.movePosition(QTextCursor::MoveOperation::End); QTextTable* table =tc.insertTable(3, 3); int row =0; QTextTableCell c00 =table->cellAt(row, 0); QTextTableCell c01 =table->cellAt(row, 1); QTextTableCell c02 =table->cellAt(row, 2); c00.firstCursorPosition().insertText(QStringLiteral("Header 0")); c01.firstCursorPosition().insertText(QStringLiteral("Header 1")); c02.firstCursorPosition().insertText(QStringLiteral("Header 2")); // this is bad table->mergeCells(1,0, 1, 3);
Everything is fine: all columns are equally spaced, until I add the last line of code. The merging of row 2 changes the size of col1, so that the table looks awfull.
Anything wrong here?Best regards
Holger -
Hi,
Which version of Qt are you using ?
On which platform ?
Can you show the results before and after you merge the cells ? -
Yeah - sure. A picture says more than words :). This is what you get w/o the merge:
And this is how it looks with the merge:
Not what I expected :(
And the Version: I am still with Qt 5 and keep my environment quite up to date: QtCreator's help shows this version: Based on Qt 5.15.2 (MSVC 2019, 64 bit)
Best regards
Holger -
Addenddum:
The effect is less bad, if the cell to be merged has set some text before it is merged:
... I can set the forground color, so that it is not visible - that can go as a workaround for nowGreetings
Holgerthis is the updated source code:
QTextDocument* td =ui->te->document(); td->clear(); QTextCursor tc(td); tc.movePosition(QTextCursor::MoveOperation::End); QTextTable* table =tc.insertTable(3, 3); table->cellAt(1, 0).firstCursorPosition().insertText(QStringLiteral("some text before merging")); table->mergeCells(1,0, 1, 3); int row =0; QTextTableCell c00 =table->cellAt(row, 0); QTextTableCell c01 =table->cellAt(row, 1); QTextTableCell c02 =table->cellAt(row, 2); c00.firstCursorPosition().insertText(QStringLiteral("Header 0")); c01.firstCursorPosition().insertText(QStringLiteral("Header 1")); c02.firstCursorPosition().insertText(QStringLiteral("Header 2"));