Results 1 to 9 of 9

Thread: How to draw vertical text via QTextEdit

Hybrid View

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

    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 ..

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

    nifei (24th February 2009)

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

    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.

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

    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 

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

    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, 10:49
  2. Replies: 1
    Last Post: 21st November 2009, 21:38
  3. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05
  5. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 07: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
  •  
Qt is a trademark of The Qt Company.