我无法将QTextFrame
放在QTextBlock
的中心:
const int RESOLUTION = 1200;
const qreal PT_MM = 25.4 / RESOLUTION;
QTextDocument textDocument;
QTextCursor cursor(&textDocument);
QTextBlockFormat blockFormat;
blockFormat.setAlignment(Qt::AlignCenter);
cursor.insertBlock(blockFormat);
QTextFrameFormat frameFormat;
frameFormat.setBorder(1);
frameFormat.setBorderStyle(QTextFrameFormat::BorderStyle_Solid);
frameFormat.setPadding(10 / PT_MM);
frameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 60));
QTextFrame *frame = cursor.insertFrame(frameFormat);
但是,即使使用选项Qt::AlignCenter
设置了相关块,框架仍是左对齐。