Introduction to the Qt graphics view framework

Source: Internet
Author: User
I used the graphics view framework of QT (using Python + pyqt) in a mouse availability test project. This is a simple introduction. Article The graphics view framework provides a simple, easy-to-use, and powerful solution for 2D plotting. If you are developing software that requires complex 2D plotting functions, consider using it.

Structure of QT 2D drawing system

Qt's 2D drawing system can be divided into two layers, including the underlying Drawing Engine and the upper-layer graphic frame.

The basic graphics engine mainly includes the qpainter, qpaintdevice, and qpaintengine classes. Among them, we generally use qpainter at the top layer, which contains a large number of painting points, draw lines, basic graphics, composite graphics, text, raster images, and other functions, similar to the DC (device context) in GDI programming or the packaging type CDC in MFC.

Based on the Basic Drawing Engine, QT also provides an element-Based Drawing and management framework. For the so-called elements, consider the commonly used UML diagram to represent a class image, it may contain three rectangles. The rectangle above contains the text of the class name, multiple attribute name texts in the middle, and multiple method name texts in the following, fill different rectangles with different brushes... regardless of the complexity of the above description, we can abstract the graphics of the class as an element, and the UML tool needs to process the selection and movement of elements and other events. The graphics view framework of QT provides strong support for the above functions.

Graphics view framework

The entire graphics view framework is composed of three main classes: qgrphicsitem, qgraphicsscene, and qgraphicsview.

An item defines elements. Its implementation usually includes drawing itself and responding to mouse/Keyboard Events on itself, and the item is drawn based on its own local coordinate system.

Scene defines the entire scenario. It contains all the elements to be drawn and places them in the appropriate positions to handle the mouse/Keyboard Events of the entire scene, changes the status of elements (whether selected or not) based on user operations, updates the areas to be re-drawn as needed, and broadcasts mouse/Keyboard Events to included elements, process overwrites between elements, and perform collision detection. The position of elements in scene is based on the world coordinate system of scene.

Finally, the view defines the scene viewport so that users can turn to view (rotate), reverse view (FLIP), partial view (CROP), and zoom out (zoom out ), the view itself is a widget (ui component), which actually provides the area of the drawing (the surface of the widget ), it can be an independent form popped up, or embedded into other UI components to form a composite UI component.

For more information, see the help documentation and examples of QT.Code.

Demo

The following is a demo image of the project. You need to drag the green icon to the blue icon and avoid hitting the yellow border.
The system needs to record the user operation time, success rate, and other information to analyze the user's input device (Mouse) availability.

If you are interested, you can guess how many items are included in the following scene.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.