QGraphicsView (OpenGL Viewport) issue with Stylesheet



  • Hi I'm developing a graphical Qt application under windows I used QGraphicsView within a QOpenGLwidget for it's viewport the problem is when I don't use any Stylsheet it works well but if I use stylsheet in any parent of QGraphicsView the background doesn't refresh (repaint) anymore and if I draw a graphicsitem it doesn't remove until I resize the QGraphicsView! what do you think ? is it a bug in Qt 5.9.2 ? or there is a solution ? of course I need to use stylesheet in my app.

    here is source code for the GraphicsView ...

    #ifdef USE_OpenGL
    
    
        QSurfaceFormat format = QSurfaceFormat::defaultFormat();
        format.setProfile(QSurfaceFormat::CoreProfile);
        format.setDepthBufferSize(24);
        format.setStencilBufferSize(8);
        format.setSamples(4);
        format.setSwapBehavior(QSurfaceFormat::DoubleBuffer);
        m_viewPort->setFormat(format);
    
        ui->gV->setViewport(m_viewPort);
    #else
        ui->gV->setCacheMode(QGraphicsView::CacheBackground);
    #endif
    
    ui->gV->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    ui->gV->setRenderHints(QPainter::Antialiasing| QPainter::HighQualityAntialiasing | QPainter::SmoothPixmapTransform| QPainter::TextAntialiasing);
    ui->gV->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ui->gV->setVerticalScrollBarPolicy  (Qt::ScrollBarAlwaysOff);
    ui->gV->setTransformationAnchor(QGraphicsView::NoAnchor);
    //ui->gV->setAutoFillBackground(false);
    //ui->gV->setAttribute(Qt::WA_OpaquePaintEvent, true);
    //ui->gV->setAttribute(Qt::WA_NoSystemBackground, true);
    
    resize(boardBaseSize);
    //ui->gV->resize(widgetBaseSize);
    

    also if I don't use OpenGL view port it again works and if I set cacheMode to QGraphicsView::CacheBackground the it works again but it doesn't use OpenGL anymore !

    thank you for your kind answers

    image of app


  • Qt Champions 2017

    Hi
    Well what do you use in the stylesheet?
    If you exclude QGraphicsView and QOpenGLwidget does it still happen?



  • Hi
    I don't have any style for QGraphicsView and QOpenGLwidget in my stylesheet, if I only set background-color for any parent widget of the QGraphicsView widget it happen and I have background color for QWidget class so all other widgets including QGraphicsView and QOpenGLwidget inherit from it.


  • Qt Champions 2017

    Hi
    As far as i know QOpenGLwidget do not use QStyle at all so
    its not unexpected that stylesheet do not work on/with it.
    So its not supported I guess.



  • Hi

    so what is the solution as I need to use the stylesheets for all other widgets ?


  • Qt Champions 2017

    @hamed_ta

    Well, use names, types or or any of the specifiers. instead of the "hit them all"
    QWidget type

    http://doc.qt.io/qt-5/stylesheet-syntax.html

    Maybe there is also something CSS2 selector syntax:

    Not sure that "not" specifier is supported.

    but there is always
    QWidget[flat="true"]
    syntax and you could just add that to the QGraphicsView and some property so it
    wont be affected but all others does.



  • @mrjj

    OK very good solution I changed all the widget styles to QWidget[acceptDrops=false] and set acceptDrops to true in QGraphicsView and its parent so the style doesn't affect on it but there is another problem ,I have a frame which contains the QGraphicsView and I need to style the frame by background-color key, but when I do so, the The problem goes back again!

    how can I set style to the frame without affecting the QGraphicsView ?

    the stye is

    background-color: qlineargradient(spread:reflect, x1:0.5, y1:1, x2:0.5, y2:0, stop:0 rgba(15, 21, 27, 255), stop:1 rgba(67, 74, 86, 255));
    border-radius: 15px;
    border-width : 0px;
    


  • @hamed_ta

    Oh I found it, I set the stylesheet of the Qframe to

    QFrame[acceptDrops=false]
    {
    	background-color: qlineargradient(spread:reflect, x1:0.5, y1:1, x2:0.5, y2:0, stop:0 rgba(15, 21, 27, 255), stop:1 rgba(67, 74, 86, 255));
    	border-radius: 15px;
    	border-width : 0px;
    }
    
    

    thank you so much


  • Qt Champions 2017

    Super :)
    Just as a note , you can add custom (dynamic) properties with the green + over the property list but
    if you never need to use drag and drop that property is just as good.



  • @mrjj

    Super!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.