THRESHE
3rd March 2008, 13:54
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
QPainter painter(this);
painter.setPen(QPen(QColor(Qt::black)));
QFont font = QFont("Times", 50, QFont::Normal);
painter.setFont(font);
QFontMetrics metrics(font);
int heightOfText = metrics.height();
painter.drawLine(0, 200 - heightOfText,
1000, 200 - heightOfText);
painter.drawLine(0, 200, 1000, 200);
painter.drawText(0, 200, "Gradient Text");
This code gives me the result displayed on the screenshot below :confused:
So My question is how to find text height without that blank space ?
(I suppose it has something with ascent and descent...)
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
QPainter painter(this);
painter.setPen(QPen(QColor(Qt::black)));
QFont font = QFont("Times", 50, QFont::Normal);
painter.setFont(font);
QFontMetrics metrics(font);
int heightOfText = metrics.height();
painter.drawLine(0, 200 - heightOfText,
1000, 200 - heightOfText);
painter.drawLine(0, 200, 1000, 200);
painter.drawText(0, 200, "Gradient Text");
This code gives me the result displayed on the screenshot below :confused:
So My question is how to find text height without that blank space ?
(I suppose it has something with ascent and descent...)