QTextCursor::mergeBlockFormat() doesn't set format.
Unsolved
General and Desktop
-
I have this function for setting block format:
void PasswordShowArea::updateBlockFormat() { insertPlainText("Some text"); QTextBlockFormat fmt = textCursor().blockFormat(); fmt.setTextIndent(g_lineNumberAreaWidth + g_lineNumberRightMargin); fmt.setLineHeight(fontMetrics().height() * 2, QTextBlockFormat::LineDistanceHeight); textCursor().mergeBlockFormat(fmt); }
Idea was to se block format in constructor but it doesn't work as expected. The function itself is called but neither text is inserted nor block format changed:
PasswordShowArea::PasswordShowArea(QWidget *parent) : QTextEdit(parent) { init(); //doesn't work // updateBlockFormat(); // works - gpt4 suggest QTimer::singleShot(0, this, &PasswordShowArea::updateBlockFormat); }
void PasswordShowArea::init() { QObject::connect(document()->documentLayout(), &QAbstractTextDocumentLayout::update, this, &PasswordShowArea::updatePasswordShowArea); setTextColor(palette().color(QPalette::Text)); }
Any ideas why this happen?
P.S. gpt suggested that the problem may be that the object at the time theupdateBlockFormat()
is called is not fully initialized -