Results 1 to 9 of 9

Thread: How to draw vertical text via QTextEdit

  1. #1
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default How to draw vertical text via QTextEdit

    hi, i need to draw text in both vertical layout and horizontal layout. like
    Attached Images Attached Images

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to draw vertical text via QTextEdit

    If your drawing yourself, you can rotate the painter , easiest way i guess

  3. The following user says thank you to aamer4yu for this useful post:

    nifei (24th February 2009)

  4. #3
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Question Re: How to draw vertical text via QTextEdit

    Quote Originally Posted by aamer4yu View Post
    If your drawing yourself, you can rotate the painter , easiest way i guess
    I want to draw the text from top to bottom on QTextDocument and call QTextCocument : : drawContents(QPainter *).

    BTW, what is the relationship between QTextDocument, QTextEdit, QTextFormat and QTextTable/ QTextList , .etc? I'm new to these classes.

  5. #4
    Join Date
    Sep 2008
    Location
    Munich
    Posts
    32
    Thanked 8 Times in 6 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw vertical text via QTextEdit

    As the previous poster said, use rotate the painter. Look in the analog clock example for how todo this.

    In Qt instead of rotating/scaling (e.g. transforming) objects, we transform the painter. It's much easier like this as soon as you get used to;-)

    This might also help you:
    - http://doc.trolltech.com/qq/qq24-textlayouts.html

    - Juergen

  6. #5
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to draw vertical text via QTextEdit

    Quote Originally Posted by jryannel View Post
    As the previous poster said, use rotate the painter. Look in the analog clock example for how todo this.

    In Qt instead of rotating/scaling (e.g. transforming) objects, we transform the painter. It's much easier like this as soon as you get used to;-)

    This might also help you:
    - http://doc.trolltech.com/qq/qq24-textlayouts.html

    - Juergen
    Thanks for your suggestion and the linked article, that is a little complicated for my project. May be rotate QPainter is the only way to draw vertical text. I supposed to edit the whole text via QTextDocument and render them to QPainter, if rotating/translating the QPainter, all the text will be rotated or translated.

    i think i have to draw the contents of QTextDocument twice, once drawing horizontal text, then rotating the QPainter and drawing the vertical text. is that right?

  7. #6
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to draw vertical text via QTextEdit

    Quote Originally Posted by nifei View Post
    Thanks for your suggestion and the linked article, that is a little complicated for my project. May be rotate QPainter is the only way to draw vertical text. I supposed to edit the whole text via QTextDocument and render them to QPainter, if rotating/translating the QPainter, all the text will be rotated or translated.

    i think i have to draw the contents of QTextDocument twice, once drawing horizontal text, then rotating the QPainter and drawing the vertical text. is that right?
    it is a little suggestion ... libqxt-0.4 is having the property to rotate your widget . especially pushButton , lineEdit ... etc ... in the designer level itself ..
    get the source and add it to your qt library ..

  8. The following user says thank you to wagmare for this useful post:

    nifei (24th February 2009)

  9. #7
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Wink Re: How to draw vertical text via QTextEdit

    Quote Originally Posted by wagmare View Post
    it is a little suggestion ... libqxt-0.4 is having the property to rotate your widget . especially pushButton , lineEdit ... etc ... in the designer level itself ..
    get the source and add it to your qt library ..
    l don't think we can use libqxt-0.4 library...for me the key problem is not how to draw vertical text now, but how to draw both vertical and horizontal text in one time. i hope this is feasible.

  10. #8
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: How to draw vertical text via QTextEdit

    I traced through QTextDocument : : drawContents (QPainter*) in hopes of QTextFormat's properties being used to control the painter, as i found QTextFormat : : setProperty ( int, QVariant) and guessed we could set QTextFormat : : UserProperty as vertical or horizontal then use this property when using the painter. however, i got lost.

    My ideas is to re-implement QTextDocument : : drawContents (QPainter * ) or other functions to get the QTextFormat's properties that have been set by users, According to the UserProperty rotate the painter or not. is this a bad idea?
    Qt Code:
    1. CustomTextDocument::someFunction(QPainter *painter, QTextFormat *format)
    2. // format might be sub class of QTextFormat, for example, QBlockTextFormat
    3. {
    4. if (format.property(QTextFormat::UserProperty).toInt() == CustomTextDocument::Vertical)
    5. {
    6. painter->save();
    7. painter->translate( xoff, yoff);// to correct the text's position
    8. painter->rotate(90);
    9. QTextDocument::someFunctioin(painter, format);
    10. // call the basic class's function to draw the text, however rotated.
    11. painter->restore();
    12. }
    13. else
    14. QTextDocument::someFunction(painter, format);
    15. // if no vertical text is needed, call basic class's function
    16. }
    To copy to clipboard, switch view to plain text mode 

  11. #9
    Join Date
    Nov 2009
    Location
    Sacramento, CA
    Posts
    24
    Thanked 1 Time in 1 Post
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to draw vertical text via QTextEdit

    So I have this code snippet to draw vertical text in a QTextEdit. However, I have 2 problems with this code. The cursor doesn't update when moved, the cursor doesn't blink, and when text is selected it doesn't draw the selection. Any ideas?
    Qt Code:
    1. void TextEdit::paintEvent(QPaintEvent *e)
    2. {
    3. QPainter painter(viewport());
    4.  
    5. painter.rotate(-90);
    6. painter.translate(-viewport()->rect().height(),0);
    7.  
    8. QAbstractTextDocumentLayout::Selection selection;
    9. selection.cursor = textCursor();
    10. selection.format = textCursor().charFormat();
    11.  
    12. QAbstractTextDocumentLayout::PaintContext ctx;
    13. ctx.cursorPosition = textCursor().position();
    14. ctx.selections.append(selection);
    15.  
    16. document()->documentLayout()->draw(&painter,ctx);
    17. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Replies: 1
    Last Post: 21st November 2009, 20:38
  3. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 14:36
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

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.