Results 1 to 7 of 7

Thread: QTextEdit align right.

  1. #1
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Question QTextEdit align right.

    Hello,

    I'm trying to achieve this in a QTextEdit.



    Any idea ?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QTextEdit align right.

    http://doc.trolltech.com/4.3/qtexted...l#setAlignment

    Compile and test this as an example:
    Qt Code:
    1. #include <QApplication>
    2. #include <QtGui>
    3.  
    4. int main(int argc, char* argv[])
    5. {
    6. QApplication app(argc, argv);
    7. QTextEdit edit;
    8. edit.setText("blablabla");
    9. edit.setAlignment(Qt::AlignRight);
    10. edit.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QTextEdit align right.

    Actually, there's a slight difference:
    [html]
    ______________
    | saddsadsa|
    | asdds|
    | dfds|
    |_____________|
    [/html]
    vs.
    [html]
    ______________
    | saddsadsa|
    | asdds |
    | dfds |
    |_____________|
    [/html]
    You can do the latter with the help of tables:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char *argv[])
    4. {
    5. QApplication a(argc, argv);
    6. QTextEdit edit;
    7. format.setAlignment(Qt::AlignRight);
    8. QTextFrame* frame = edit.textCursor().insertTable(1, 1, format);
    9. QTextCursor cursor(frame);
    10. cursor.insertText("saddsadsa\nasdds\ndfds");
    11. edit.show();
    12. return a.exec();
    13. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit align right.

    Or use a horizontal layout with a spacer that will push your text edit widget to the right.

  5. #5
    Join Date
    Jan 2007
    Location
    Paris
    Posts
    459
    Thanks
    98
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4 Qt5

    Default Re: QTextEdit align right.

    Man, that was tough.

    I found absolutely no way to do it with a layout:

    I needed a stretchable QParagraph with height for width justified on the right.
    I had to reimplement my own widget to place it manually.

    The layout wouldn't let me put a stretchable area that let the paragraph take as much space as it can.

    Here is the result:



    Ask me if you need some code.

    Regards.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QTextEdit align right.

    But what exactly is your goal?

  7. #7
    Join Date
    Oct 2009
    Posts
    4
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: QTextEdit align right.

    Hey Bunjee, i will need the code for QTextEdit align right

Similar Threads

  1. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 16:55
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. QTextEdit Justify align making work
    By dec0ding in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 12:02

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.