Search code examples
c++cssqtqgraphicsview

Qt QGraphicsView and StyleSheets


Can I use CSS/stylesheets to style a item in QGraphicsView, like QGraphicsWidget? If yes, how?


Solution

  • I don't think it's directly possible, at least if you apply a stylesheet to the QGraphicsView itself it will not affect any widgets inside of it. However, you can assign a stylesheet to a widget before adding it into the scene, then it will keep it's style after being added:

    QGraphicsScene scene;
    QPushButton b;
    
    b.setStyleSheet("QPushButton{background-color:red}");
    scene.addWidget(&b);
    
    QGraphicsView view(&scene);
    view.show();