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. QGraphicsView (OpenGL Viewport) issue with Stylesheet
Forum Updated to NodeBB v4.3 + New Features

QGraphicsView (OpenGL Viewport) issue with Stylesheet

Scheduled Pinned Locked Moved Solved General and Desktop
10 Posts 2 Posters 3.9k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    hamed_ta
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hamed_ta
        wrote on last edited by hamed_ta
        #3

        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.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          2
          • H Offline
            H Offline
            hamed_ta
            wrote on last edited by
            #5

            Hi

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

            mrjjM 1 Reply Last reply
            0
            • H hamed_ta

              Hi

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

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @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.

              H 1 Reply Last reply
              1
              • mrjjM mrjj

                @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.

                H Offline
                H Offline
                hamed_ta
                wrote on last edited by hamed_ta
                #7

                @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;
                
                H 1 Reply Last reply
                0
                • H hamed_ta

                  @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;
                  
                  H Offline
                  H Offline
                  hamed_ta
                  wrote on last edited by hamed_ta
                  #8

                  @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

                  1 Reply Last reply
                  2
                  • mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by mrjj
                    #9

                    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.

                    H 1 Reply Last reply
                    1
                    • mrjjM mrjj

                      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.

                      H Offline
                      H Offline
                      hamed_ta
                      wrote on last edited by
                      #10

                      @mrjj

                      Super!

                      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