[Qt-interest] QTextCursor::insertBlock() at the beginning of a QTextEdit will prepend an empty line
Mohammed Sameer
msameer at foolab.org
Sun Jul 3 18:48:15 CEST 2011
Hi,
I'm trying to make the first line in a QTextEdit centered by using this sample code:
QTextEdit e;
QTextCursor cursor(e.textCursor());
QTextBlockFormat fmt;
fmt.setAlignment(Qt::AlignHCenter);
cursor.insertBlock(fmt);
cursor.insertText("Centered line");
cursor.insertBlock(QTextBlockFormat());
cursor.insertText("Non centered line");
e.setTextCursor(cursor);
My problem is I get an empty line before the centered line. Seems the only way to
hack around it is to set the cursor position to 0 after I insert all the text
then use QTextCursor::deleteChar().
Any better way ?
Cheers,
--
GPG-Key: 0xA3FD0DF7 - 9F73 032E EAC9 F7AD 951F 280E CB66 8E29 A3FD 0DF7
Debian User and Developer.
Homepage: www.foolab.org
More information about the Qt-interest-old
mailing list