Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Problem with vertical alignment in QTextTableFormat

Problem with vertical alignment in QTextTableFormat

Scheduled Pinned Locked Moved General and Desktop
2 Posts 1 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    David_Gil
    wrote on last edited by
    #1

    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!

    1 Reply Last reply
    0
    • D Offline
      D Offline
      David_Gil
      wrote on last edited by
      #2

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

      Thank you

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved