PDA

View Full Version : Qt::AlignVCenter does not work on QTextTable



sipahi
5th February 2013, 10:05
I created QTextTable:


QTextDocument *document=new QTextDocument(this);
QTextCursor cursor(document);
cursor.movePosition(QTextCursor::Start);

QTextTableCellFormat cellFormat;
cellFormat.setLeftPadding(7);
cellFormat.setRightPadding(7);

QBrush blackBrush(Qt::SolidPattern);
QTextTableFormat tableFormat;
tableFormat.setAlignment(Qt::AlignCenter);
tableFormat.setBorderBrush(blackBrush);
tableFormat.setBorder(0.5);
tableFormat.setCellSpacing(0);
tableFormat.setBorderStyle(QTextFrameFormat::Borde rStyle_Solid);
tableFormat.setWidth(QTextLength(QTextLength::Perc entageLength, 100));
QTextTable *table = cursor.insertTable(10,10,tableFormat);

QTextBlockFormat centerAlignment;
centerAlignment.setAlignment(Qt::AlignCenter);

table->mergeCells(0,0,10,5);
cursor = table->cellAt(0, 0).firstCursorPosition();
cursor.setBlockFormat(centerAlignment);
cursor.insertText("text");

I want to write text in the middle of cell vertically and horizontally
But my text is in the middle horizontally but it is not in the middle vertically.
Also Qt::AlignVCenter and Qt::AlignBottom do not work.

Santosh Reddy
5th February 2013, 16:53
Set the format on the cell object..


QTextCharFormat format = table->cellAt(0, 0).format();
format.setVerticalAlignment(QTextCharFormat::Align Middle);
table->cellAt(0, 0).setFormat(format);

sipahi
5th February 2013, 18:14
Thank you @Santosh Reddy