Can't use QPainter in QOpenGlWidget with OpenGL 3.3
-
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()); }