1

when i use qopenglwidget and qaxwidget in qt,i meet a strange problem that qopenglwidget does not show correctly.i dont know why.the code is like that:

QTabWidget *tt=new QTabWidget;
MyOpenGLWidget *openGL = new MyOpenGLWidget ();
QAxWidget *native = new QAxWidget();
native->setControl(QStringLiteral("{f587310d-5306-494d-87e2-88334b46e781}"));
native->setAttribute(Qt::WA_NativeWindow);
native->setAttribute(Qt::WA_DontCreateNativeAncestors);
tt->addTab(native,"n");
tt->addTab(openGL,"o");

MyOpenGLWidget inherit from QOpenGLWidget and has an override method paintEvent,like:

void MyOpenGLWidget ::paintEvent(QPaintEvent *event)
{
QPainter painter;
painter.begin(this);
painter.setRenderHint(QPainter::Antialiasing);
painter.fillRect(event->rect(), QColor(255,255,0));
painter.end();
}

and i also set app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings); in main function.

the problem is

1.the background of MyOpenGLWidget is black,not yellow that i expect

2.when i change tt->addTab(native,"n"); tt->addTab(openGL,"o"); to tt->addTab(openGL,"o"); tt->addTab(native,"n"); MyOpenGLWidget show right

i create a test project in https://github.com/hankern/Test-QOpenGLWidget

1
  • i think the context of qaxwidget affects the context of qopenglwidget,but how can i assign a new context for qopenglwidget
    – han
    Aug 22, 2015 at 10:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.