简体   繁体   中英

Qt Application with QTabWidget, QGraphicsScene and QPushButton

I want to create a Qt application with a QTabWidget, where each tab contains a QGraphicsView and a QGraphicsScene to draw a polygon on a Cartesian plane. example: first tab for a triangle, second for square, etc...

So, I create my qt application and then: - inside my class derived from QDialog, I create a QVBoxLayout, I've added my widget to this, and I've inserted it into my QTabWidget, created with QDesigner: I repeat this operation for each tab of QTabWidget. I want to know if it's a bad practice to add a QGraphicsScene into a tab in this way or to redefine all the classes from qwidget, view, and scene.

  • out of the QTabwidget, i have some QPushButtons that do some operations on the QGraphicsScene's polygons: when i click on a polygon, i want to do some operations through the QpushButton, like sum the angles (only on the polygon that I've clicked). How do I communicate to the QPushButton (out of the QTabWidget) that I've clicked a polygon and which one I've clicked(inside QTabWidget)?
  • the private data field of my_scene contains a QList of triangles (derived from QGraphicsPolygonItem)

https://i.stack.imgur.com/Pu329.jpg

I want to know if it's a bad practice

Generally speaking no, it isn't.

If you are ok with the functionality of some class you should use this class. If you need to extend it in any way you should subclass from this class and add everything you need.

It's true not only for Qt classes but for any other classes written by you or somebody else. It's one of the basic principles of inheritance.

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