Results 1 to 2 of 2

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

  1. #1
    Join Date
    Sep 2008
    Thanked 42 Times in 41 Posts
    Qt products
    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
    Graz, Austria
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    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.


  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


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.