Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-51216

Text rendered on QOpenGLWidget with QPainter looks corrupted

    XMLWordPrintable

Details

    • Bug
    • Resolution: Out of scope
    • P2: Important
    • None
    • 5.5.0
    • GUI: OpenGL
    • None
    • I'm using Qt 5.5 on Windows 7 with GeForce GTX 460 graphics card.

    Description

      Hi,

      I'm trying to figure out how to render text on a QOpenGLWidget. I read that QPainter could be used. I am able to render the text but the text looks corrupted (see attachment). Here is a small example code to reproduce the issue.

      #include <QApplication>
      #include <QOpenglWidget>
      #include <QPainter>
      
      class MyOpenGLWidget : public QOpenGLWidget
      {
      public:
      	MyOpenGLWidget(){}
      
      	void initializeGL() { glClearColor(1.f, 1.f, 1.f, 1.f); }
      
      	void resizeGL(int w, int h) { glViewport(0, 0, w, h); 	}
      
      	void paintGL()
      	{
      		glClear(GL_COLOR_BUFFER_BIT);
      		
      		QPainter painter(this);
      		painter.setPen(Qt::black);
      		painter.setFont(QFont("Arial", 16));
      		painter.drawText(0, 0, width(), height(), Qt::AlignCenter, "Hello World!");
      		painter.end();
      	}
      };
      
      int main(int argc, char **argv)
      {
         QApplication app(argc, argv);
         MyOpenGLWidget wnd;
         wnd.resize(400, 300);
         wnd.show();
         return app.exec();
      }
      

      Is this a bug? I am doing something wrong? Or is there a better way to do this?

      Thanks!

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            esabraha Eskil Abrahamsen Blomfeldt
            belgiansteve Steve
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes