Results 1 to 6 of 6

Thread: multiline drawtext draw all in same line

  1. #1
    Join Date
    Jan 2013
    Posts
    4

    Default multiline drawtext draw all in same line

    hi,

    i will draw a multiline text with alignment AlignBottom, but it draw all lines in same line.

    fontAlign = Qt::AlignHCenter | Qt::AlignBottom;
    p->drawText(rect, fontAlign, str);

    see attachment

    what can I do, thanks

    Peter
    Attached Images Attached Images

  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: multiline drawtext draw all in same line

    What do rect and str contain?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2013
    Posts
    4

    Default Re: multiline drawtext draw all in same line

    hi

    rect {x1=135 y1=165 x2=449 y2=359}
    str:

    "
    Hier
    Text
    eingeben
    "

    here a pic with Top alignment

    a.jpg

  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: multiline drawtext draw all in same line

    So it works for top but fails for bottom, correct? Can you prepare a minimal compilable example reproducing the problem?

    This seems to work fine:
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class Widget : public QWidget {
    4. public:
    5. Widget() : QWidget() {}
    6. protected:
    7. void paintEvent(QPaintEvent *) {
    8. QPainter p(this);
    9.  
    10. p.drawText(rect(), Qt::AlignHCenter|Qt::AlignBottom, "Hier\nText\neingeben");
    11. }
    12. };
    13.  
    14. int main(int argc, char **argv) {
    15. QApplication app(argc, argv);
    16. Widget w;
    17. w.resize(449, 359);
    18. w.show();
    19. return app.exec();
    20. }
    To copy to clipboard, switch view to plain text mode 

    Did you remember to put newline characters (\n) in your string? I can't see them in what you posted.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jan 2013
    Posts
    4

    Default Re: multiline drawtext draw all in same line

    ok thanks,
    I'll try it tomorrow

  6. #6
    Join Date
    Jan 2013
    Posts
    4

    Default Re: multiline drawtext draw all in same line

    hi,

    now works fine.
    It was the (\ n), my fault.

    thanks

Similar Threads

  1. Replies: 3
    Last Post: 5th February 2011, 07:31
  2. Draw Line
    By sagirahmed in forum Newbie
    Replies: 5
    Last Post: 18th October 2010, 07:49
  3. QPainter::drawText, draw big text
    By franco.amato in forum Newbie
    Replies: 3
    Last Post: 18th March 2010, 08:32
  4. Draw a line
    By Daan in forum KDE Forum
    Replies: 1
    Last Post: 27th August 2009, 17:29
  5. Best way to draw a Line
    By JimDaniel in forum Qt Programming
    Replies: 1
    Last Post: 19th January 2008, 09:57

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.