Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Can't use QPainter in QOpenGlWidget with OpenGL 3.3
Forum Updated to NodeBB v4.3 + New Features

Can't use QPainter in QOpenGlWidget with OpenGL 3.3

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 425 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    Gerx
    wrote on last edited by
    #1

    I'm trying to use QPainter in my QOpenGLWidget. But it only works with 3.0 OpenGL version. What is the problem?

    Here is my code.
    
    #include <QApplication>
    #include <Q
    MainWindow>
    #include "window.h"
    
    int main(int argc, char *argv[])
    {
      QApplication app(argc, argv);
    
      QSurfaceFormat format;
    
      format.setRenderableType(QSurfaceFormat::OpenGL);
      format.setProfile(QSurfaceFormat::CoreProfile);
      format.setVersion(3,3);
    
      // Set widget up
       Window *widget = new Window;
       widget->setFormat(format);
    
      // Set the window up
      QMainWindow window;
      window.setCentralWidget(widget);
      window.resize(QSize(800, 600));
      window.show();
    
      return app.exec();
    }
    

    If i'll do setVersion(3,0) everything will work fine. But my shaders won't start up.

    And QOpenGLWidget subclass

    #define WINDOW_H
    
    #include <QOpenGLWidget>
    #include <QOpenGLFunctions>
    
    class QOpenGLShaderProgram;
    
    class Window : public QOpenGLWidget,
                   protected QOpenGLFunctions
    {
      Q_OBJECT
    
    // OpenGL Events
    public:
    
      void initializeGL();
      void resizeGL(int width, int height);
      void paintGL();
    
    };
    
    #endif // WINDOW_H
    

    and simpliest example.

    #include <QPainter>
    
    
    void Window::initializeGL()
    {}
    
    void Window::resizeGL(int width, int height)
    {}
    
    void Window::paintGL()
    {
          QPainter p(this);
          p.setPen(Qt::red);
          p.drawLine(rect().topLeft(), rect().bottomRight());
    }
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved