Results 1 to 7 of 7

Thread: how to set text alignmet to right ?

  1. #1
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Question how to set text alignmet to right ?

    hi,
    i want to align the text to the right in a QTextEdit
    i tryed the following code but it failed
    Qt Code:
    1. mainText->setAlignment(Qt::AlignRight);
    To copy to clipboard, switch view to plain text mode 
    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

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to set text alignmet to right ?

    The Alignment is a Paragraph Propertiy then QtextEdit::setAlignment set Alignment of the current Paragrah
    Try with
    Qt Code:
    1. QTextOption options = mainText->document()->defaultTextOption();
    2. options.setAlignment(Qt::AlignRight);
    3. mainText->document()->setDefaultTextOption(options);
    To copy to clipboard, switch view to plain text mode 

    For TreeWidget you have to use QTreeWidgetItem::setTextAlignment() for all items in the tree.
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to set text alignmet to right ?

    Qt Code:
    1. QApplication::setLayoutDirection(Qt::RightToLeft);
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to set text alignmet to right ?

    This affects all visible text on Application (menu, Title Bar, ...).
    I don't think mismael85 needs this
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,518 Times in 1,388 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: how to set text alignmet to right ?

    Quote Originally Posted by mcosta View Post
    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.
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to set text alignmet to right ?

    You are right.
    I hope that mismael85 intends set Text Alignment.
    A camel can go 14 days without drink,
    I can't!!!

  7. #7
    Join Date
    Feb 2008
    Posts
    154
    Thanks
    12
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: how to set text alignmet to right ?

    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
    Qt Code:
    1. QTextOption options = mainText->document()->defaultTextOption();
    2. options.setAlignment(Qt::AlignRight);
    3. mainText->document()->setDefaultTextOption(options);
    To copy to clipboard, switch view to plain text mode 
    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.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  3. Match the text beetween two string
    By dreamer in forum Qt Programming
    Replies: 4
    Last Post: 20th May 2008, 14:48
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 15:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.