Results 1 to 6 of 6

Thread: adjust Font size to a given rect when drawText

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #4
    Join Date
    May 2006
    Posts
    788
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    49
    Thanked 48 Times in 46 Posts

    Default Re: adjust Font size to a given rect when drawText

    Quote Originally Posted by yartov View Post
    I have to adjust a Font size, when the user resized Widget where I draw text in a given rectangle.
    Can somebody to give me a hint or point me to the right example?
    Thanks in advance
    You can draw a arial 6point to a 2000 pixel QWidget and is not need to change point size
    only think Vector ...

    QPainterPath is your friend ...


    Qt Code:
    1. void ButtonAction::paintText()
    2. {
    3. QPainter *p = new QPainter(this);
    4. p->setRenderHint(QPainter::Antialiasing);
    5. const int borderI = 25;
    6. /* button text */
    7. QPainterPath textPath;
    8. textPath.addText(borderI,borderI * 2,fontText,textBut); //// fontText is any font() //// textBut text one line
    9. /* fix view from text */
    10. const QRectF reo = textPath.boundingRect();
    11. TXTrect = reo;
    12. /* tanslate text rect to rect window button */
    13. p->setWindow ( reo.x() , reo.y() , reo.width() , reo.height() );
    14. /* color text */
    15. p->setPen(Qt::NoPen);
    16. p->setBrush(colText);
    17. p->drawPath(textPath);
    18. Pm = p->deviceMatrix();
    19. p->end();
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. The following user says thank you to patrik08 for this useful post:

    yartov (14th May 2008)

Similar Threads

  1. Font size calculation when painting in a QImage
    By Ishark in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2007, 22:22
  2. Replies: 3
    Last Post: 30th January 2007, 07:35
  3. QTreeView font size not being set
    By forrestfsu in forum Qt Tools
    Replies: 2
    Last Post: 12th October 2006, 13:53

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.