我创建了 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::BorderStyle_Solid);
tableFormat.setWidth(QTextLength(QTextLength::PercentageLength, 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");
我想在单元格的中间垂直和水平地写文本但是我的文本在水平的中间但它不在垂直的中间。Qt::AlignVCenter 和 Qt::AlignBottom 也不起作用。我试过这个答案https://stackoverflow.com/a/10329809/1997790但它不起作用。