Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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


  • Lifetime Qt Champion

    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:
    972666f2-28d3-4c43-9f41-faeda7558ee4-image.png

    And this is how it looks with the merge:
    0ef20a63-40eb-4af6-a14b-e073c07778b6-image.png

    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:
    6ef38cc4-7c84-400c-9d3d-643b1d4fe0af-image.png ... I can set the forground color, so that it is not visible - that can go as a workaround for now

    Greetings
    Holger

    this 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"));
    

Log in to reply