Tables in QTextEdit does not respect constraints



  • Hi everybory,

    I been trying to insert a table into a QTextEdit with fixed length, using insertTable with QTextTableFormat.

        QTextCursor cursor = textEdit->textCursor();
        QTextTableFormat fmt;
        fmt.setColumns(wNumColumn);
        // add constrains
        QVector<QTextLength> constraints;
        for (int i=0;i<wNumColumn;i++) constraints.append(QTextLength(QTextLength::FixedLength,wSizeFixed));
        fmt.setColumnWidthConstraints(constraints);
        fmt.setCellSpacing(0);
        cursor.insertTable(wNumColumn,wNumRow,fmt);
    
    

    The table cells does not respect the fixed constraints that I had set, if a single word size is bigger than the column size.
    0_1486565359781_upload-df92ea5b-fc88-4fc8-85a1-fefc2ded5a50

    If I use words smaller than the column size, the constraints were respected.
    0_1486565279705_upload-32b9d885-f3b9-49fc-89ed-265b916775ed

    BUT.. if I add "22222....." til the limit of the document and the QTextEdit breaks the line, the table respects size constraints.

    0_1486565442280_upload-ab113378-1e29-4801-9bd3-b4af25b3903c

    Once the table were resize by the line break, all cells respect the width constraints inserted.

    How could I fix this behavior? I tried to find some properties in the QTextTableFormat and (QTextTable object returned by the function insertTable) but so far nothing.

    Thanks in advance...



  • I found the problem.

    Apparently the QTextTable does not limit the maximum table size when you fixed the column size.

    fmt.setWidth((wNumColumn-1)*wSizeFixed);
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.