QTextCharFormat setfont not working
Solved
General and Desktop
-
// [ Text 폰트 사이즈 변경 ] QFont f("Arial", 140, QFont::Bold); QTextCharFormat format = cursor.charFormat(); format.setFont(f); //format.setFontPointSize(140); //cursor.setCharFormat(format); cursor.mergeCharFormat(format);
Can you look at my code? The font attribute is not applied, so I want to change the text size or font.
-
QTextCursor cursor(this->ui.textEdit->textCursor()); cursor.movePosition(QTextCursor::Start); // 프레임 생성 QTextFrame* topFrame = cursor.currentFrame(); QTextFrameFormat topFrameFormat = topFrame->frameFormat(); topFrameFormat.setPadding(16); // 전체 Padding 여백 topFrame->setFrameFormat(topFrameFormat); QFont f("Bahnschrift SemiBold", 30); QTextCharFormat textFormat; textFormat.setFont(f); QTextFrameFormat referenceFrameFormat; referenceFrameFormat.setBorder(1); referenceFrameFormat.setPadding(8); referenceFrameFormat.setPosition(QTextFrameFormat::InFlow); referenceFrameFormat.setWidth(QTextLength(QTextLength::VariableLength, 40)); cursor.insertFrame(referenceFrameFormat); // [ 제목 표시줄 생성 ] { // [ Text 가운데 정렬 코드 ] QTextBlockFormat textBlockFormat = cursor.blockFormat(); textBlockFormat.setAlignment(Qt::AlignCenter); cursor.mergeBlockFormat(textBlockFormat); cursor.insertText("Measure Summary", textFormat); cursor.setPosition(topFrame->lastPosition()); } // [ 측정 정보 란 생성 ] { QTextBlockFormat textBlockFormat1 = cursor.blockFormat(); textBlockFormat1.setAlignment(Qt::AlignCenter); cursor.mergeBlockFormat(textBlockFormat1); textFormat.setFontPointSize(15); referenceFrameFormat.setPosition(QTextFrameFormat::FloatRight); referenceFrameFormat.setWidth(QTextLength(QTextLength::PercentageLength, 25)); cursor.insertFrame(referenceFrameFormat); cursor.insertText("Measure Info", textFormat); cursor.insertBlock(); textFormat.setFontPointSize(10); cursor.insertText("Report Time\t[data]", textFormat); cursor.insertBlock(); cursor.insertText("Operator\t[data]", textFormat); cursor.insertBlock(); cursor.insertText("Instrument\t[data]", textFormat); cursor.insertBlock(); cursor.insertText("Version\t[data]", textFormat); cursor.insertBlock(); cursor.insertText("Temperature\t[data]", textFormat); }
QTextBlockFormat textBlockFormat1 = cursor.blockFormat(); textBlockFormat1.setAlignment(Qt::AlignCenter); cursor.mergeBlockFormat(textBlockFormat1);
The 2nd QTextBlockFormat's text can't be aligned either.
-
https://forum.qt.io/topic/130298/qtextimageformat-widget-grab-not-working
Can you look at the content?