Results 1 to 2 of 2

Thread: how to make draw text word wrapped to fit the given font size plus rectangle

  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 make draw text word wrapped to fit the given font size plus rectangle

    hi friends,

    i am having a QGraphicsTextItem and QGraphicsItem where the user can give input text to the text item using setTextInteractionFlags.
    now i wanted to draw the same text on the QGraphicsItem paint function .
    so i passed the text item "text", "font" and the "boundingRect" to the QGraphicsItem paint event
    TEXT = "theCurrentText"
    FONT = "theCurrentFontSize"
    boundingRect = m_bounds;


    and painted as

    Qt Code:
    1. QFont segoeFont("Segoe Regular");
    2.  
    3.  
    4. segoeFont.setPointSizeF(theCurrentFontSize );
    5. p->setFont(segoeFont);
    6. p->setPen(actPen);
    7. QFontMetricsF fma( p->font());
    8.  
    9. QRectF bounds = fma.boundingRect(QRectF(0, 0, m_bounds.width() , 0), Qt::TextWordWrap, theCurrentText);
    10. p->fillRect(bounds, Qt::white);
    11. p->drawText(bounds, Qt::TextWordWrap, theCurrentText);
    To copy to clipboard, switch view to plain text mode 

    but the text is not getting wrapped at any point . even hundreds of word i have given but still the words are getting cropped but showing in a single line.
    my graphicstextitem
    InitialGraphicsItem.jpg
    and my graphicsitem
    finalEyGsText(UgObject).jpg

    i checked the debug statements of the the graphicstext item and graphicsitem .
    The Ey Text item bounding rect value is: QRectF(-2,-2 1909.22x62)
    The Ey text item font size value coming is: 8.25

    The Ey Text bounding rect value is: QRectF(0,0 1909x86)
    The Ey font size value coming is: 8.25


    both bounding rect and font size are coming similar and both are child of same graphicsitem ..

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

  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: how to make draw text word wrapped to fit the given font size plus rectangle

    I would assume you are passing an incorrect rectangle to QFontMetrics::boundingRect().
    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.


Similar Threads

  1. Replies: 5
    Last Post: 18th August 2014, 22:48
  2. Replies: 1
    Last Post: 30th March 2012, 17:46
  3. Replies: 3
    Last Post: 5th February 2011, 08:31
  4. Replies: 10
    Last Post: 25th June 2009, 03:09
  5. Simple word-wrapped popup box
    By hardgeus in forum Qt Programming
    Replies: 1
    Last Post: 9th April 2008, 21:01

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.