PDA

View Full Version : QPainter native painting



Talei
25th September 2012, 05:36
Hello,
I have problem with QPainter and native painting.
In short it doesn't work.

For example I use in paintEvent() this code to draw simple quad:


void myWidget::paintEvent(QPaintEvent *e)
{
QPainter p(this);
p.beginNativePainting();

glBegin(GL_QUADS);
glColor3ub(0,0,255);
glVertex2d(0, 0);
glVertex2d(0, height());
glColor3ub(255,0,0);
glVertex2d(width(), height());
glVertex2d(width(), 0);
glEnd();

qDebug() << "--- OpenGL paint" << this->width() << this->height() << p.paintEngine()->type();

p.endNativePainting();

}

paintEngine()->type() is always 10 == Rester.

So the question:
how to initialize OpenGL painting with the QPainter? (qt 4.8.1)

I don't know if it's lack of the sleep but with the 4.7. this worked fine.

wysota
25th September 2012, 10:19
Does myWidget inherit QGLWidget?

Talei
25th September 2012, 20:52
No.

I see (after sleep) where the problem lies.
QGLContext is non existing, in 4.7 I used setGraphicsSybstem opengl - qt created one for MainWindow automatically so I could do native in non OGL widget.

Sub classing QGLWidget solves problem.