QGraphicsView overlay on top of QOpenGLWidget?



  • I have an idea that sounds possible on paper but I've been having trouble implementing.

    I have a QOpenGLWidget that is used to view a large high resolution image. (It's using OpenGL for efficiency since there's a lot of cuts made to the image using clipping, etc). I'm trying to overlay a QGraphicsView+QGraphicsScene on top of the QOpenGLWidget to draw shapes and lines on top of the image, and interact with those shapes and lines.

    I've been having a couple problems with this. First, I can't figure out a way to overlay the QGraphicsView on top of the QOpenGLWidget. I've tried a number of suggestions, including setting the two widgets to the same cell in a grid layout.

    QGridLayout * layout = new QGridLayout;
    layout->setContentsMargins(0, 0, 0, 0);
    layout->addWidget(m_GraphicsView);
    layout->addWidget(m_ImageGL);
    m_Owner->setLayout(layout);
    

    However, this isn't working. I'm only seeing one of the widgets. I figure this might be a transparency issue, so I tried setting some transparency flags.

    m_GraphicsView->viewport()->setAttribute(Qt::WA_TranslucentBackground);
    m_GraphicsView->viewport()->setAttribute(Qt::WA_NoSystemBackground);
    m_GraphicsView->viewport()->setAttribute(Qt::WA_NoBackground);
    m_GraphicsView->viewport()->setWindowFlags(Qt::FramelessWindowHint);
    m_GraphicsView->viewport()->setAttribute(Qt::WA_NoSystemBackground);
    m_GraphicsView->viewport()->setStyleSheet("background: transparent");
    
    m_GraphicsView->setAttribute(Qt::WA_TranslucentBackground);
    m_GraphicsView->setAttribute(Qt::WA_NoSystemBackground);
    m_GraphicsView->setAttribute(Qt::WA_NoBackground);
    m_GraphicsView->setWindowFlags(Qt::FramelessWindowHint);
    m_GraphicsView->setAttribute(Qt::WA_NoSystemBackground);
    m_GraphicsView->setStyleSheet("background: transparent");
    
    
    m_ImageGL->viewport()->setAttribute(Qt::WA_TranslucentBackground);
    m_ImageGL->viewport()->setAttribute(Qt::WA_NoSystemBackground);
    m_ImageGL->viewport()->setAttribute(Qt::WA_NoBackground);
    m_ImageGL->viewport()->setWindowFlags(Qt::FramelessWindowHint);
    m_ImageGL->viewport()->setAttribute(Qt::WA_NoSystemBackground);
    m_ImageGL->viewport()->setStyleSheet("background: transparent");
    
    m_ImageGL->setAttribute(Qt::WA_TranslucentBackground);
    m_ImageGL->setAttribute(Qt::WA_NoSystemBackground);
    m_ImageGL->setAttribute(Qt::WA_NoBackground);
    m_ImageGL->setWindowFlags(Qt::FramelessWindowHint);
    m_ImageGL->setAttribute(Qt::WA_NoSystemBackground);
    m_ImageGL->setStyleSheet("background: transparent");
    

    I might have gone a little overboard here, but I'm setting every flag that I've seen suggested and I'm still not seeing what I'm expecting. Does anyone have any ideas?


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Did you try with QStackedLayout with StackingMode set to StackAll ?

    Hope it helps