May 8, 2012

David_Gil David_Gil
Lab Rat
31 posts

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:

  1.     QSettings settings;
  2.     QString addressText = textEdit->document()->toPlainText();
  3.     envelopeDocument = new QTextDocument(this);
  4.  
  5.     printer.setResolution(QPrinter::HighResolution);
  6.     printer.setPrinterName(settings.value("printerName").toString());
  7.     printer.setOrientation(QPrinter::Landscape);
  8.     printer.setFullPage(true);
  9.  
  10.     QFont font("Trebuchet MS");
  11.     QSizeF paperSize;
  12.  
  13.     QTextFrame *rootFrame = envelopeDocument->rootFrame();
  14.     QTextCursor cursor(rootFrame);
  15.     cursor.movePosition(QTextCursor::Start);
  16.  
  17.     QTextTableFormat tableFormat;
  18.     //Horizontal alignment works fine (I tried left, center and right)
  19.     tableFormat.setAlignment(Qt::AlignRight);
  20.     //But when I add any vertical alignment, table renders in top left corner.
  21.     tableFormat.setAlignment(Qt::AlignVCenter);
  22.     //With Qt::AlignCenter, table aligns horizontally, but not vertically
  23.    
  24.     tableFormat.setWidth(QTextLength(QTextLength::PercentageLength,40));
  25.  
  26.     QTextTable *table = cursor.insertTable(1,1,tableFormat);
  27.  
  28.     QTextCharFormat textFormat;
  29.     textFormat.setFont(font);
  30.     textFormat.setFontPointSize(12);
  31.     printer.setPaperSize(QPrinter::DLE);
  32.     paperSize.setWidth(printer.width());
  33.     paperSize.setHeight(printer.height());
  34.     envelopeDocument->setPageSize(paperSize);
  35.     cursor = table->cellAt(0,0).firstCursorPosition();
  36.     cursor.insertText(addressText,textFormat);

If this is a bug, is there any workaround?

Thank you!

1 reply

May 8, 2012

David_Gil David_Gil
Lab Rat
31 posts

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

Thank you

 
  ‹‹ XML DOM empty      Save application settings ››

You must log in to post a reply. Not a member yet? Register here!