0

Sounds simple, I want to draw text at a point on the display, so that it is aligned both horizontally and vertically by its centre.

However it doesn't appear to be quite so simple, I've used other libraries where all I have to do is set the text alignment, then draw the text at the specified point.

Qt isn't so simple.

SPlatten
  • 5,334
  • 11
  • 57
  • 128

1 Answers1

2

Even we use FTGL to render texts.

But in QT there is method for controlling alignment.

I guess you use QPainter::drawText to draw the texts.

There is a library function:

void QPainter::drawText(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0)

Here the flags argument is a bitwise OR operator with lot of alignment options.

I think for your case, you can use Qt::AlignHCenter | Qt::AlignVCenter

Refer documentation:

http://doc.qt.io/qt-4.8/qpainter.html#drawText-13

Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34