Qt World Summit: Register Today!

Qt QGraphicsView OpenGL viewport issue

  • I subclassed QGraphicsView (to extend functionality) and put it to my gui using QtDesigner with promoting it to necessary class.

    To accelerate graphics rendering i desided to set vieport of my graphics view to QGLWidget (but left all scene items be rendered by QPainter). Doing it like was suggested by Qt doc and other people: ui->graphicsView->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));

    Unfortunatly because of gui style main widget, which is used as container to put all other widgets in layouts, has attribute setAttribute(Qt::WA_TranslucentBackground);. It was made for drop shadow effect in minimized program state.

    Removing that flag gives necessary graphics rendering acceleration but all stylesheets of main window are cease to work (eg. buttons do not react on hover event).

    Here is code totally reproducing the problem (im using Qt5.13):

    #include <QtOpenGL/QGL>
    main_form::main_form(QWidget *parent)
        : QWidget(parent)
        resize(400, 300);
        effect = new QGraphicsDropShadowEffect;
        QHBoxLayout *main_lay = new QHBoxLayout;
        QWidget *handler = new QWidget(this);
        handler->setStyleSheet(QString("background-color: white;"));
        QTreeWidget *tree = new QTreeWidget(this);
        QGraphicsView *view = new QGraphicsView(this);
        QHBoxLayout *handle_lay = new QHBoxLayout;
        view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
        delete effect;

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Might be a silly remark but your code does not contain any button that you are mentioning in your issue description.

    Can you show pictures of what you are getting.

  • It doesnt contain any buttons because i decided to create minimal example (from the zero) without unnecessary things.


    if you compile code i showed in previous message you will get exatly the same effect.

  • Still looking for help.

Log in to reply