Results 1 to 8 of 8

Thread: Drawing Text

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Drawing Text

    Hi,
    I have QtEmbedded 4.4.1. I am trying to draw text within a rectangle (as per the picture), however, there is too much spacing between the lines. I know this is probably related to the QFontMetrics::lineSpacing().
    I have a button rectangle, and a text rectangle, I am drawing the text rectangle inside the button rectangle. The text rectangle coordinates are relative to the button coordinates, not the screen coordinates, that is why I have to draw an adjusted button rectangle.
    Anyways, this works, but the font display spacing is too large, and I must also consider different translations ( accents on the chars, etc).
    image.png is actual
    spec.png is required

    Qt Code:
    1. QFontMetrics fm(txtFont);
    2. qDebug() << fm.lineSpacing() << fm.leading() << fm.height();
    3. QRectF adjRect(rect().adjusted(txtRect.x(),txtRect.y(),
    4. -txtRect.x(), -(rect().bottom() - (rect().y()+txtRect.y()+txtRect.height()))));
    5. painter->drawText(adjRect,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
    6. painter->drawRect(adjRect); // for debugging
    To copy to clipboard, switch view to plain text mode 

    1) Can I reduce the line spacing? (I would like to increase the font size)
    2) Is this the best method to draw text taking into consideration other languages? I worry that the top line will cut-off accents.
    Attached Images Attached Images

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. Replies: 2
    Last Post: 23rd July 2012, 08:42
  3. Drawing Rich Formatted Text with QPainter
    By millsks in forum Qt Programming
    Replies: 1
    Last Post: 5th March 2009, 19:59
  4. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  5. Drawing antialiased text on Windows very slow
    By Rawk in forum Qt Programming
    Replies: 13
    Last Post: 14th May 2007, 14:13

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.