Horizontal alignement of QTextFrame

Asked by At

I'm not able to center a QTextFrame in a 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);

but the frame is left-aligned, even if the related block is set with the option Qt::AlignCenter.

0 Answers