简体   繁体   中英

QGLWidget::renderText() creates some downwards shifted letters

I created a class derived from QGLWidget:

class OpenGLWidget : public QGLWidget

I want to write some text on top of the OpenGL widget. Therefore I used the renderText() method inside the paintGL() of my class:

QString s = QString("AaBbCcDd");
renderText(10, 20, s);        // picture line 1

In the created text on top of my widget some letters are shifted downwards / upwards.

Have a look at this picture .

For example in the first line of the picture 'C', 'G', 'O' are shifted upwards and '4', '5' are shifted downwards.

I tried to change the font and the font size, but this only changed the letters, which are shifted, not the problem itself:

QFont font = QFont("Arial");
font.setPointSize(18);
renderText(10, 50, s, font);    // picture line 2

font = QFont("Times");
font.setPointSize(18);
renderText(10, 80, s, font);    // picture line 3

font = QFont("Courier");
font.setPointSize(18);
renderText(10, 110, s, font);   // picture line 4

font = QFont("Courier");
font.setPointSize(16);
renderText(10, 140, s, font);   // picture line 5

Does anybody know how to bring the letters on a straight line?

I also tried the QPainter::drawText() method instead of the renderText() inside the paintGL() of my class:

QPainter painter(this);
QString s = QString("AaBbCcDd");
painter.drawText(10, 20, s);

This method causes the same problem.

I am using Qt 4.7.4 with Qt Creator 2.4.1 on Mac OS 10.7.

This is a known bug in Qt 4.8.x. It affects Mac Qt-based applications that are run under OS X 10.7 and 10.8 (Lion and Mountain Lion). If you run your application under OS X 10.6 (Snow Leopard) you will not see the problem.

Qt 5.0.x fixes the renderText() problem for OS X 10.7 and 10.8 but is still too flaky to be used as a substitute for the more-solid 4.8.x builds.

Sadly, the Qt gods have not (yet) taken it upon themselves to retrofit the 4.8.x build with the fix from the 5.0.x build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM