Results 1 to 7 of 7

Thread: Height of the text without balnk space at the top

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Qt products
    Qt4
    Platforms
    MacOS X Windows
    Thanks
    15
    Thanked 11 Times in 10 Posts

    Default Height of the text without balnk space at the top

    Hello everyone
    I need to center text in a rectangle and I use QFontMetrics::height() to know the height of it.
    But it doesn't return me the height but instead it gives me blank space at the top
    Qt Code:
    1. QPainter painter(this);
    2. painter.setPen(QPen(QColor(Qt::black)));
    3. QFont font = QFont("Times", 50, QFont::Normal);
    4. painter.setFont(font);
    5. QFontMetrics metrics(font);
    6.  
    7. int heightOfText = metrics.height();
    8. painter.drawLine(0, 200 - heightOfText,
    9. 1000, 200 - heightOfText);
    10. painter.drawLine(0, 200, 1000, 200);
    11. painter.drawText(0, 200, "Gradient Text");
    To copy to clipboard, switch view to plain text mode 
    This code gives me the result displayed on the screenshot below
    So My question is how to find text height without that blank space ?
    (I suppose it has something with ascent and descent...)
    Attached Images Attached Images
    • File Type: jpg 1.jpg (8.1 KB, 8 views)
    Last edited by THRESHE; 3rd March 2008 at 14:04.
    C++ & AMD forever

Similar Threads

  1. Unhandled exception in qatomic
    By NewGuy in forum Qt Programming
    Replies: 14
    Last Post: 23rd July 2013, 09:49
  2. linking user space and kernel space programs with qmake
    By zielchri in forum Qt Programming
    Replies: 9
    Last Post: 8th March 2006, 23:11

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.