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);
}
void MyEditor::sltAlignRight()
{
editor->setAlignment(Qt::AlignRight);
editor->setFocus(Qt::OtherFocusReason);
}
void MyEditor::sltAlignLeft()
{
editor->setAlignment(Qt::AlignLeft);
editor->setFocus(Qt::OtherFocusReason);
}
To copy to clipboard, switch view to plain text mode
and this one for changing text direction:
void MyEditor::sltChangeLayoutDirection()
{
if (f.layoutDirection() != Qt::RightToLeft) {
f.setLayoutDirection(Qt::RightToLeft);
} else {
f.setLayoutDirection(Qt::LeftToRight);
}
editor->textCursor().mergeBlockFormat(f);
editor->setFocus(Qt::OtherFocusReason);
}
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);
}
To copy to clipboard, switch view to plain text mode
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.
Bookmarks