简体   繁体   中英

Overriding QGraphicsView paintEvent function in Qt Designer

Im writing some simple python application using PyQt and QtDesigner. I've designed mainView in designer which has a QGraphicsView and some buttons inside. My question is, how should I draw shapes on that QGraphicsView?

Without QtDesigner, I would have created class extending QGraphicsView and overriden its paintEvent() method. However, Designer generates single Ui_MainWindow class, so I can't set it's QGraphicsView field to my specific subclass.

You'll want to promote the QGraphicsView to your own class that subclasses QGraphicsView . To learn how to promote widgtes in Qt Designer, see this SO post: How do I use promote to in Qt Designer in pyqt4?

In your subclass, you can override the paintEvent method is usual.

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