PDA

View Full Version : QTextEdit align



mero
28th March 2011, 02:38
Hello,

I have QTextEdit with:


mainTextEdit->append(strContent);

// align
if (strAlign == "center")
mainTextEdit->setAlignment(Qt::AlignCenter);
else
mainTextEdit->setAlignment(Qt::AlignLeft);



and everythink is ok,
but if I select by mouse text with align center and I add next text - text aligned center will be aligned left ....

(Qt::AlignCenter | Qt::AlignAbsolute) is not working..

setAligment should work only to last block not to text selected by mouse ...
any suggestion ?

BalaQT
28th March 2011, 08:31
hi,
i hav tried with a similar example, the alignments are working fine.

setAligment should work only to last block not to text selected by mouse
for me , with mouse selection of text blocks, the alignment is still in centre only.

bala

mero
28th March 2011, 14:36
Example of this strange bug:

6165
6166
6167

MarekR22
28th March 2011, 15:47
read documentation QTextEdit::setAlignment

Sets the alignment of the current paragraph to a. Valid alignments are Qt::AlignLeft, Qt::AlignRight, Qt::AlignJustify and Qt::AlignCenter (which centers horizontally).
Current paragraph is where cursor is. By default when cursor is not set cursor is treated as set to end of document.
append method ignores current cursor so you have incoherency in code.

mero
29th March 2011, 04:43
so you have incoherency in code.

any example how can i fix it?

MarekR22
29th March 2011, 09:10
Go lower. Update content of QTextDocument (QTextEdit::document) using QTextCursor.


QTextCursor cursor(ui->lineEdit->document());
cursor.movePosition(QTextCursor::End);

cursor.insertBlock(textBlockFormatInUse);
// OR
// cursor.insertBlock();
// cursor.mergeBlockFormat(alignBlockFormat);

cursor.insertText("New text to insert");