View Full Version : how to set text alignmet to right ?
mismael85
26th June 2008, 11:03
hi,
i want to align the text to the right in a QTextEdit
i tryed the following code but it failed
mainText->setAlignment(Qt::AlignRight);
i also want to show a tree elements from right to left
i build QTreeWidget and i successed to fill it with items
but the tree nodes appeares from left i want them from right
please help me.
and thank you
mcosta
26th June 2008, 11:27
The Alignment is a Paragraph Propertiy then QtextEdit::setAlignment set Alignment of the current Paragrah
Try with
QTextOption options = mainText->document()->defaultTextOption();
options.setAlignment(Qt::AlignRight);
mainText->document()->setDefaultTextOption(options);
For TreeWidget you have to use QTreeWidgetItem::setTextAlignment() for all items in the tree.
QApplication::setLayoutDirection(Qt::RightToLeft);
mcosta
26th June 2008, 11:46
This affects all visible text on Application (menu, Title Bar, ...).
I don't think mismael85 needs this
This affects all visible text on Application (menu, Title Bar, ...).
I don't think mismael85 needs this
Well, he said that he wants tree nodes to appear from right to left. Adjusting alignment doesn't affect tree nodes. ;) Of course one can also change the layout direction of a single widget with QWidget::setLayoutDirection(), but does it make sense if the layout direction of the rest of the application is different? To me it sounds like a quite confusing UI design at least.
mcosta
26th June 2008, 14:04
You are right.
I hope that mismael85 intends set Text Alignment.
mismael85
26th June 2008, 17:08
thank you all every thing works fine now.
first for the text alignment int the QTextEdit i wrote the following code and the result was
perfect
QTextOption options = mainText->document()->defaultTextOption();
options.setAlignment(Qt::AlignRight);
mainText->document()->setDefaultTextOption(options);
and mcosta was right on this
and for jpn i used your code and it also was nice the tree nodes became from
left to right but it does no thing for the text int the QTextEdit so i used both codes.
thank you all.
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.