Results 1 to 2 of 2

Thread: how to get the boundingrect of multi line text using qfontmetrics

  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 how to get the boundingrect of multi line text using qfontmetrics

    hi friends,

    I want to know how i can get the boundingRect of the multi line text from the QFontMetrics.
    im having a qgraphicsItem where i have to draw text .
    while drawing im using the fontmetrics bounding rect to define the rect of the text to draw .

    Qt Code:
    1. QFontMetrics fontMtic(segoeFont);
    2. m_bounds = fontMtic.boundingRect(theCurrentText);
    3. p->drawText(QRectF(theTextItemPos, m_bounds.size()),Qt::TextWordWrap, theCurrentText);
    To copy to clipboard, switch view to plain text mode 

    but when the theCurrentText is coming with multi line or having new line in it , the bounding rect value of the fontmetric return me the height of the first line only .

    I want to get the complete boundary height for the text.

    can any one please help me to solve this problem .
    "Behind every great fortune lies a crime" - Balzac

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: how to get the boundingrect of multi line text using qfontmetrics

    Since your drawText() call is one of the overloads that takes flags,you need to use one of the boundingRect() calls that uses the same flags.

    Alternatively, there is a drawText() overload that takes an options QRect* as its last argument. If you pass in a pointer to a local QRect variable, e.g. "&m_bounds", it will set that variable to the bounding rect actually used for drawing the text.

    Cheers,
    _

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

    wagmare (23rd April 2014)

Similar Threads

  1. Length of text in QFontMetrics
    By Screamer2087 in forum Qt Programming
    Replies: 1
    Last Post: 6th January 2014, 23:24
  2. Replies: 2
    Last Post: 27th February 2013, 12:24
  3. A crash in QFontMetrics::boundingRect()
    By npirocanac in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 5th February 2013, 11:47
  4. How to specify QRect argument to QFontMetrics::boundingRect()
    By John Mcgehee in forum Qt Programming
    Replies: 0
    Last Post: 13th October 2010, 04:50
  5. Multi-line elided text?
    By WinchellChung in forum Newbie
    Replies: 1
    Last Post: 6th February 2008, 16:37

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.