Problem with vertical alignment in QTextTableFormat



  • Hi!

    I have a problem with vertical alignment of a table in a QTextDocument. I suspect it's related to bug https://bugreports.qt-project.org/browse/QTBUG-6979 , but before thinking about bugs, I'd like to know whether there's a problem in the code that I don't see and experts probably will:

    @
    QSettings settings;
    QString addressText = textEdit->document()->toPlainText();
    envelopeDocument = new QTextDocument(this);

    printer.setResolution(QPrinter::HighResolution);
    printer.setPrinterName(settings.value("printerName").toString());
    printer.setOrientation(QPrinter::Landscape);
    printer.setFullPage(true);
    
    QFont font("Trebuchet MS");
    QSizeF paperSize;
    
    QTextFrame *rootFrame = envelopeDocument->rootFrame();
    QTextCursor cursor(rootFrame);
    cursor.movePosition(QTextCursor::Start);
    
    QTextTableFormat tableFormat;
    //Horizontal alignment works fine (I tried left, center and right)
    tableFormat.setAlignment(Qt::AlignRight);
    //But when I add any vertical alignment, table renders in top left corner.
    tableFormat.setAlignment(Qt::AlignVCenter);
    //With Qt::AlignCenter, table aligns horizontally, but not vertically
    
    tableFormat.setWidth(QTextLength(QTextLength::PercentageLength,40));
    
    QTextTable *table = cursor.insertTable(1,1,tableFormat);
    
    QTextCharFormat textFormat;
    textFormat.setFont(font);
    textFormat.setFontPointSize(12);
    printer.setPaperSize(QPrinter::DLE);
    paperSize.setWidth(printer.width());
    paperSize.setHeight(printer.height());
    envelopeDocument->setPageSize(paperSize);
    cursor = table->cellAt(0,0).firstCursorPosition();
    cursor.insertText(addressText,textFormat);
    

    @

    If this is a bug, is there any workaround?

    Thank you!



  • Finally, if this is a bug, where should I look to fix it? For my app, table vertical alignment is crucial.

    Thank you


Log in to reply
 

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