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. Qt QGraphicsView OpenGL viewport issue
Forum Update on Monday, May 27th 2025

Qt QGraphicsView OpenGL viewport issue

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 624 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.
  • M Offline
    M Offline
    mccat
    wrote on last edited by
    #1

    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)
    {
        setWindowFlag(Qt::FramelessWindowHint);
        setAttribute(Qt::WA_TranslucentBackground);
        resize(400, 300);
    
        effect = new QGraphicsDropShadowEffect;
        effect->setBlurRadius(25);
        effect->setOffset(0);
        setGraphicsEffect(effect);
    
        QHBoxLayout *main_lay = new QHBoxLayout;
        setLayout(main_lay);
    
        QWidget *handler = new QWidget(this);
        handler->setStyleSheet(QString("background-color: white;"));
        QTreeWidget *tree = new QTreeWidget(this);
        QGraphicsView *view = new QGraphicsView(this);
    
        main_lay->addWidget(handler);
        QHBoxLayout *handle_lay = new QHBoxLayout;
        handler->setLayout(handle_lay);
        handle_lay->addWidget(tree);
        handle_lay->addWidget(view);
    
        view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
    }
    
    main_form::~main_form()
    {
        delete effect;
    }
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mccat
        wrote on last edited by
        #3

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

        qWIXm.png

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

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mccat
          wrote on last edited by
          #4

          Still looking for help.

          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