Congratulations to our 2022 Qt Champions!

QPainter::drawText display corrupted text on a QOpenGLWidget

  • Hi,
    I have a QOpenGLWidget. This widget is used to display different elements:

    • a background image (OpenGL texture),

    • a list of selected pixels (OpenGL texture displayed on the background)

    • A text displaying the distance between two selected pixels (QPainter::drawText)

    All OpenGL drawing are enclosed by a beginNativePainting/EndNativePainting. But I have a strange behavior on the text drawing.

    At the beginning of the application, when the layer with selected pixels has not yet been displayed, if I'm using the measure tool, text is correctly displayed and still be correctly displayed once the selected pixels layer is activated.

    But, if I start the application, activate the display of the selected pixels layer, and then use my measure tool, displayed text is corrupted. And it is no more possible to have a correct display (even with the selected pixels layer disabled). The text is displayed has in the below image:
    0_1524640385224_corrupted text.PNG
    In fact this text looks like I had a shift between each pixel row. Any ideo of the origin of this problem?

  • Problem found. In my program I have a line

        func->glPixelStorei(GL_UNPACK_ALIGNMENT, 1);

    As long as the layer is not displayed, this line is not executed. So, once active, I supposes that it has a side effect on the loading of the glyphs. Once glyphs are loaded with standard alignment everything works well. But, with a byte alignment something is broken.

    Now it is not normal that a call to an OpenGL function changes the way glyphs are loaded.

  • Lifetime Qt Champion


    Glad you found out and thanks for sharing !

    What version of Qt are you using ?
    On which platform ?
    Did you check the bug report system to see if it's something known ?