Results 1 to 5 of 5

Thread: problem in drawText

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

    Default problem in drawText

    hi friends,

    i got a problem in QPainter::drawText()
    i try to insert a new line "\n" to a QString text "Maintenance" as

    string = "main \ntenance";

    but it displayed as main[]tenance .. a box like undefined char is showing instead of
    "main
    tenance"

    so i tried
    Qt Code:
    1. string.insert(4, "\n"); //same as previous
    2. string.insert(4, QChar::LineSeparator); //same as previous
    To copy to clipboard, switch view to plain text mode 

    this one is working fine if i use QGraphicsTextItem

    please help me solving this issue ..
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in drawText

    This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.

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

    wagmare (29th July 2009)

  4. #3
    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: problem in drawText

    Use the QPainter::drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.
    can't get it .. how to wrap the text .. ?
    "Behind every great fortune lies a crime" - Balzac

  5. #4
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: problem in drawText

    Quote Originally Posted by wagmare View Post
    can't get it .. how to wrap the text .. ?
    Buddy this is damm easy. Use:
    Qt Code:
    1. void QPainter::drawText ( const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0 )
    To copy to clipboard, switch view to plain text mode 
    And use this property in argument flags.
    Qt Code:
    1. Qt::TextWordWrap
    To copy to clipboard, switch view to plain text mode 

  6. #5
    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: problem in drawText

    thank you very much gokul
    "Behind every great fortune lies a crime" - Balzac

Similar Threads

  1. Problem in using QHttp with QTimer
    By Ferdous in forum Newbie
    Replies: 2
    Last Post: 6th September 2008, 12:48
  2. Weird problem: multithread QT app kills my linux
    By Ishark in forum Qt Programming
    Replies: 2
    Last Post: 8th August 2008, 09:12
  3. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  4. Why is drawText so terribly slow?
    By Ntoskrnl in forum Qt Programming
    Replies: 8
    Last Post: 1st August 2008, 19:15
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

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.