参考 C++ 中的例子:Qt\Qt5.11.1\Examples\Qt-5.11.1\widgets\graphicsview\diagramscene


The Diagram Scene example is an application in which you can create a flowchart diagram. It is possible to add flowchart shapes and text and connect the shapes by arrows as shown in the image above. The shapes, arrows, and text can be given different colors, and it is possible to change the font, style, and underline of the text.
The Qt graphics view framework is designed to manage and display custom 2D graphics items. The main classes of the framework are QGraphicsItem, QGraphicsScene and QGraphicsView. The graphics scene manages the items and provides a surface for them. QGraphicsView is a widget that is used to render a scene on the screen. See the Graphics View Framework for a more detailed description of the framework.
In this example we show how to create such custom graphics scenes and items by implementing classes that inherit QGraphicsScene and QGraphicsItem.
In particular we show how to:
Create custom graphics items.
Handle mouse events and movement of items.
Implement a graphics scene that can manage our custom items.
Custom painting of items.
Create a movable and editable text item.
The example consists of the following classes:
MainWindow creates the widgets and display them in a QMainWindow. It also manages the interaction between the widgets and the graphics scene, view and items.
DiagramItem inherits QGraphicsPolygonItem and represents a flowchart shape.
TextDiagramItem inherits QGraphicsTextItem and represents text items in the diagram. The class adds support for moving the item with the mouse, which is not supported by QGraphicsTextItem.
Arrow inherits QGraphicsLineItem and is an arrow that connect two DiagramItems.
DiagramScene inherits QGraphicsDiagramScene and provides support for DiagramItem, Arrow and DiagramTextItem (In addition to the support already handled by QGraphicsScene).

QT5.9Demo

王维波《Qt5.9 C++开发指南》(配套资源)

本文介绍Qt图形视图框架的使用,通过创建自定义图形场景和项,实现流程图绘制应用。文章涵盖自定义图形项、鼠标事件处理、自定义绘图、可编辑文本项等关键技术点。
799

被折叠的 条评论
为什么被折叠?



