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) { 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; }
-
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.