PDA

View Full Version : Does QTextEdit have problem with combination of text direction and alignment?



golnaz
29th December 2008, 20:05
hi freinds,

I use a QTextEdit in my app, and want it to support both rtl & ltr text directions, while having ability to change alignment, independent of the text direction.

I wrote these slots for setting alignment:


void MyEditor::sltAlignRight()
{
editor->setAlignment(Qt::AlignRight);
editor->setFocus(Qt::OtherFocusReason);
}

void MyEditor::sltAlignLeft()
{
editor->setAlignment(Qt::AlignLeft);
editor->setFocus(Qt::OtherFocusReason);
}


and this one for changing text direction:


void MyEditor::sltChangeLayoutDirection()
{
QTextBlockFormat f = editor->textCursor().blockFormat();

if (f.layoutDirection() != Qt::RightToLeft) {
f.setLayoutDirection(Qt::RightToLeft);
} else {
f.setLayoutDirection(Qt::LeftToRight);
}
editor->textCursor().mergeBlockFormat(f);

editor->setFocus(Qt::OtherFocusReason);
}


the problem is, when sltChangeLayoutDirection() is triggered, to make the text right-to-left, direction changes successfully, but editor content is aligned at right side.
but editor->alignment() returns Qt::AlignLeft.
now, if I call sltAlignRight(), editor content will be aligned at left side!

I wonder if this is my fault in coding, or it's really a bug of QTextEdit?
Did anyone have the same problem?

I use ubuntu8.04 with kde4.1.
thanks a lot.

jpn
30th December 2008, 12:01
Just a wild guess, does it make any difference if you combine the alignment with Qt::AlignAbsolute?



editor->setAlignment(Qt::AlignRight | Qt::AlignAbsolute);

golnaz
30th December 2008, 21:35
thank you very much my friend, it works. :)

you really helped me, thanks for your attention. :)