Results 1 to 10 of 10

Thread: Vertical Orientation of Text.

  1. #1
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Vertical Orientation of Text.

    Qt Code:
    1. #include <QtGui>
    2.  
    3. class W : public QWidget {
    4. public:
    5. W() : QWidget(){}
    6.  
    7. protected:
    8. void paintEvent(QPaintEvent *e){
    9.  
    10. QTextLayout textLayout( "Hello How are you!");
    11. QFontMetrics fontMetrics(QApplication::font());
    12. int leading = fontMetrics.leading();
    13. int height = 0;
    14. qreal widthUsed = 0;
    15. textLayout.beginLayout();
    16. while (1) {
    17. QTextLine line = textLayout.createLine();
    18. if (!line.isValid())
    19. break;
    20.  
    21. line.setLineWidth(9);
    22. //line.setNumColumns (1);
    23. height += leading;
    24. line.setPosition(QPoint(0, height));
    25. height += line.height();
    26. widthUsed = qMax(widthUsed, line.naturalTextWidth());
    27. }
    28. textLayout.endLayout();
    29. QWidget::paintEvent(e);
    30. QPainter p(window());
    31. QPen pe = p.pen();
    32. pe.setWidth(4);
    33. pe.setColor(Qt::red);
    34. p.setPen(pe);
    35. textLayout.draw(&p, QPoint(0, 0));
    36. }
    37. };
    38.  
    39. int main(int argc, char **argv){
    40. QApplication app(argc, argv);
    41. W w;
    42. w.show();
    43. w.resize(300,200);
    44. return app.exec();
    45. }
    To copy to clipboard, switch view to plain text mode 
    I am getting the output as attachments;
    but I wants as
    H
    e
    l
    l
    o

    H
    o
    w

    a
    r
    e

    y
    o
    u
    !
    What should I do in code for this;
    Attached Images Attached Images
    • File Type: png h.png (19.6 KB, 83 views)
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  2. #2
    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: Vertical Orientation of Text.

    The easiest way is to add a newline after every character.

  3. #3
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Vertical Orientation of Text.

    Quote Originally Posted by wysota View Post
    The easiest way is to add a newline after every character.
    But it is not a way of vertical orientation of text.
    I am facing the same problem in the below thread specially for white space character.
    Space problem in QTextEdit
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  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: Vertical Orientation of Text.

    If you want to use the text layout object, then at least set the line width before creating lines. You can use QFontMetrics to check how wide the line should be to incorporate one character of the current font.

  5. #5
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Vertical Orientation of Text.

    If you want to use the text layout object, then at least set the line width before creating lines
    How a way I set the line before creating the text layout object.
    Please suggest me a function for that or give me a example.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  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: Vertical Orientation of Text.


  7. #7
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Vertical Orientation of Text.

    Quote Originally Posted by wysota View Post
    Probably, this is function of QTextLine. How a way I use in my code?
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  8. #8
    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: Vertical Orientation of Text.

    Please take a look at the example in QTextLayout docs.

  9. #9
    Join Date
    Aug 2007
    Location
    Gorakhpur, India
    Posts
    254
    Thanks
    8
    Thanked 14 Times in 14 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Vertical Orientation of Text.

    Quote Originally Posted by wysota View Post
    Please take a look at the example in QTextLayout docs.
    I have seen already and by the use of it I developed this above code. But QTextLayout::setLineWidth() I am not getting this function to set the text layout width previously before the line create.
    Anurag Shukla
    A man who never makes mistake is the man who never does anything! Theodre Rosvelt!

  10. #10
    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: Vertical Orientation of Text.

    Set it after you create the line but before you create another... The point is to force a single character on each line. Or consider not using the text layout at all and simply drawing each character yourself using QPainter::drawText.

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 10:49
  2. Problem pasting text into a QTextEdit
    By Spockmeat in forum Qt Programming
    Replies: 8
    Last Post: 14th March 2009, 15:36
  3. Vertical text in a QTextDocument
    By Angelo Moriconi in forum Qt Programming
    Replies: 6
    Last Post: 7th February 2008, 06:30
  4. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 13:05
  5. Editable text in QGraphicsView
    By wysota in forum Qt Programming
    Replies: 8
    Last Post: 24th February 2007, 16: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.