简体   繁体   中英

Qt QGraphicsView and StyleSheets

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

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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM