In the "Qt-mvc Graphical view Framework", we learned about the three most basic classes in the Qt Graph view framework, figuring out their relationship, and we will continue to delve into the Qgraphicsview,qgraphicescene,qgraphicsitem three classes. Learn what you need to know about your development and how to understand these three classes.
Qgraphicsview: A class for display, in order to implement an entity's
Class name |
Functions and characteristics |
|
Coordinates |
Qgraphicsview (View Class) |
1) provides a visual window for displaying entities. 2) You can have multiple views in the same scene, or you can provide several different views of the same data. 3) Qgraphicsview is a large window part that can be scrolled, and if you need to use OpenGL, you can Qgraphicsview::setviewport set the view to Qglwidget. 4) Receive input events from the keyboard and mouse and translate them into scene events (convert the coordinate system to the coordinates of the scene). 5) using the transformation matrix function Qgraphicsview::setmatrix can transform the coordinates of the scene to realize the Zoom and rotate. 6) Qgraphicsview provides Qgraphicsview::maptoscene and The qgraphicsview::mapfromscene is used to convert the coordinates of the scene. |
|
Indirectly inherited from the qwidget, the coordinate system is naturally the same as the Qwidget |
Qgraphicescene (Scene Class) |
1) Elements of the container, itself is not visible, must be connected by the view class to display and interoperate with the outside world. 2) The main task of the scene class is to provide an operator interface and event delivery to the elements he contains, and to manage the state of individual entities (such as selection and focus processing). |
|
|
Qgraphicsitem (Entity Class) |
1) The base class for each entity in the scene, which can be any object you want. Specific needs to be achieved, such as you want him to be a picture, Then inherit the class and then use the combination of methods, contains a Qpixmap object inside the class. There are two virtual functions which need to be implemented Qgraphicsitem::boundingrect defining the bounds of an entity Qgraphicsitem::p aint defines the redraw of an entity 2) Function:
- Handling Mouse and keyboard events
- Handling Drag and Drop events
- Group
- Collision detection
In addition, the entity has its own coordinate system, and also provides elements and scenes. An entity can also exchange itself through Qgraphicsitem::matrix, which can contain sub-entities. |
|
Boundaries define themselves, relative to themselves Qgraphicsitem::p aint drawing is the upper-left corner of the entity boundary as the origin. For Qgraphicsscene, He is also the origin of the positive center of the element, because when using Qgraphicsitem::setpos (0,0), the center of the entity can coincide with the center of the qgraphicsscene at just one point. |
The above is the parsing of the Qt-mvc graphical view framework, which I will parse at the code instance level.
QT-MVC Graphical View Framework decomposition