In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-28 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
The main content of this article is to explain "what is the Qt graphical view framework", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Now let the editor to take you to learn "what is the Qt graphical view framework"!
Introduction to the Qt View Framework
The graphical View Framework (The Graphic View Framework) is used to manage and interact with a large number of customized 2D graphics projects, as well as view widgets for visualization projects, supporting zooming and rotation.
the framework includes an event propagation architecture that allows precise double-precision interaction with items in the scene. The project can handle keystroke events, mouse down, move, release, and double click events, and can track mouse movements. The graphical view uses the BSP (Binary Space Partitioning, that is, binary spatial partitioning) tree to provide very fast read project discovery, so it can reality large scenes in real time, even if there are millions of projects. The graphical view provides a way to transform a project-based model view into a project where multiple views can view a single scene and the scene contains different geometry.
Scene (The Scene)
QGraphicsScene provides a graphical view of the scene, which has the following responsibilities:
Provide a quick interface for managing a large number of projects (element projects); (the actual measurement of the same area can not overlap much, drawing will stutter)
Propagate events to each item
Manage project status, such as selection and focus processing
Provides unconverted rendering; used primarily for printing; the scene is used as a container for QGraphicsItem objects. Add the item to the scene by calling QGraphicsItem::additem (), and then retrieve the item by calling one of several item discovery functions. QGraphicsItem::items () and its overloads return all items that are contained or intersected by a point, rectangle, polygon, or regular vector path. QGraphicsItem::itemAt () returns the topmost item at a specific point. All project discovery functions return items in descending stacking order (that is, the first returned item is the top and the last item is the bottom).
QGraphicsScene scene;QGraphicsRectItem * rect = scene.addRect (QRectF (0,0,100,100)) QTransform transform;;QGraphicsItem * item = scene.itemAt (50,50, transform); / / item = = rect
QGraphicsScene's event propagation architecture arranges for scenario events to be delivered to projects and manages propagation between projects. If the scene receives a mouse down event at a location, the scene passes the event to any item at that location. QGraphicsScene also manages some item states, such as item selection and focus. You can select items in the scene by calling QGraphicsScene::setSelectionArea (), passing any shape. The work function can also be used as the selection area of eraser in QGraphicsView. To get a list of all currently selected items, call QGraphicscene::selecteditems (). Another state that QGraphicsScene processes is whether the item has keyboard input focus. You can set focus on an item by calling QGraphicScene::setFocusItem () or QGraphicsItem::setFocus (), or you can get the current focus item by calling QGraphicscene::focusItem (). Finally, , QGraphicScene allows you to render part of the scene to the drawing device through the QGraphicScene::render () function. You can learn more about this content in the print section.
View (The View)
QGraphicsView provides a view widget that can visualize the contents of the scene. You can attach multiple views to the same scene to provide multiple viewports in the same dataset. The view widget is a scroll area and provides scroll bars for navigation in large scenes. To enable OpenGL support, you can set QGLWidget as the viewport by calling QGraphicsView::setViewport ().
QGraphicsScene scene;myPopulateScene (& scene) QGraphicsView view (& scene); view.show ()
Before sends events to the visual scene, the view receives input events from the keyboard and mouse and converts them into scene events (converting the coordinates used into scene coordinates, where appropriate). uses the transformation matrix QGraphicsView::transform (), and the view can transform the coordinate system of the scene. This allows for advanced navigation features such as zooming and rotation. For convenience, qgraphicsView also provides functions for converting between view and scene coordinates: QGraphicsView::mapToScene () and QGraphicsView::mapFromScene ().
Projects (The Item): graphic element
QGraphicsItem is the base class for graphic items in the scene. The graphical view provides several standard items for typical shapes, such as rectangles (QGraphicsRectItem), ellipses (QGraphicsEllipsItem), and text items (QGraphicsTextItem), but the most powerful QGraphicsItem feature is available when writing customizations. In addition, QGraphicsItem supports the following features:
Mouse down, move, release and double click events, as well as mouse hover events, wheel events, and context menu events
Keyboard input focus and keystroke events
Drag and drop
Grouping, through paternity, through QGraphicsItemGroup
Collision detection
The project is located in the local coordinate system, and similar to QGraphicsView, it also provides many features for mapping coordinates between projects and scenes and from project to project. In addition, like QGraphicsView, it can transform its coordinate system using the matrix: QGraphicsItem::Transform (). This is useful for rotating and scaling individual items. items can contain other items (children). The transformation of a parent is inherited by all its children. However, regardless of the cumulative transformation of an item, all of its functions (for example, QGraphicsItem::contains (), QGraphicsItem::boundingRect (), QGraphicsItem::collectsWith ()) still operate in local coordinates. QGraphicsItem supports conflict detection through the QGraphicsItem::shape () function and QGraphicsItem::collipswith (), both of which are virtual functions. All conflict detection will be handled for you by returning the shape of the item from QGraphicsItem::shape () as the local coordinate QPaineterPath,QGraphicsItem. However, if you want to provide your own collision detection, you can re-implement QGraphicsItem::CollipsWith ().
Classes in the Qt graphical view framework
classes provide a framework for creating interactive applications.
Drawing view coordinate system
The graphical view is based on the Cartesian coordinate system; the location and geometry of the project in the scene are represented by two sets of numbers: X and Y coordinates. When you view a scene with an unconverted view, a unit in the scene is represented by a pixel on the screen. Note: because the drawing view uses the qt coordinate system, the inverted Y coordinate system (Y growth up) is not supported. There are three valid coordinate systems * * in the drawing view: project coordinates, scene coordinates, and view coordinates. To simplify the implementation, the graphical view provides convenient functionality that allows you to map between the three coordinate systems. When is rendered, the scene coordinates of the graphic view correspond to the logical coordinates of the QPainer, and the view coordinates are the same as the device coordinates. The relationship between logical coordinates and device coordinates will be explained later.
Project coordinates
The project is in its own local coordinate system. Their coordinates are usually centered on the center point (0re0), which is also the center of all transformations. Geometric primitives in a project coordinate system are often referred to as project points, project lines, or project rectangles. When creates a custom item, you only need to worry about the item coordinates; QGraphicsScene and QGraphicsView will perform all the transformations for you. This makes it very easy to implement customizations. For example, if you receive a mouse down or drag input event, the event location is given in the project coordinates. The QGraphicsItem::contains () virtual function returns true if a point is in the item, or false otherwise, accepting a point parameter in the item coordinates. Similarly, the bounding rectangle and shape of the item are in the item coordinates. The location of the in the project is the coordinate of the project center point in its parent coordinate system; sometimes called the parent coordinate. In this sense, scenarios are treated as "parents" of all unparented items. The location of the top-level project is in the scene coordinates. The child coordinates are relative to the parent coordinate. If the child coordinates are not converted, the difference between the child coordinates and the parent coordinates is the same as the distance between the items in the parent coordinates. For example, if the unconverted child is precisely positioned at the center of its parent, the coordinate system of the two items will be the same. However, if the position of the child object is (10d0), the point (0mag10) of the child object will correspond to the point (10d10) of its parent object. because the location and transformation of the item are relative to the parent, the coordinates of the child are not affected by the transformation of the parent, although the transformation of the parent implicitly converts the child. In the above example, even if the parent is rotated and scaled, the child's (0mag10) point still corresponds to the parent's (10p10) point. However, relative to the scene, the child object follows the transformation and position of the parent object. If you scale the parent object (2xrem 2x), the position of the child object will be in the scene coordinates (20d0), and its (10d0) point will correspond to the point on the scene (40pc0). because QGraphicsItem::pos () is one of the few exceptions, the function of QGraphicsItem operates in item coordinates, regardless of the conversion of the item or any of its parents. For example, the bounding rectangle of a project (that is, QGraphicsItem::boundingRect ()) is always given in the project coordinates.
Scene coordinates
The scene represents the base coordinate system of all its items. The scene coordinate system describes the location of each top-level project and forms the basis of all scene events passed from the view to the scene. Each project in the scene has a scene location and bounding rectangle (QGraphicsItem::scenePos () and QGraphicsItem::sceneBoundingRect ()), except for its local item pos and bounding rectangle. The scene location describes the position of the project in the scene coordinates, and its scene boundary rectangle forms the basis of how QGraphicsScene determines which areas of the scene have changed. Changes in the scene are communicated through the QGraphicsScene::changed () signal, and the parameters are a list of scene rectangles.
View coordinates
The view coordinates are the coordinates of the widget. Each cell in the view coordinates corresponds to one pixel. This coordinate system is special in that it is relative to the widget or viewport and is not affected by the observed scene. The upper left corner of the visual area of the QGraphicsView is always (0J0) and the lower right corner is always (width and height of the visual area). All mouse events and drag-and-drop events are initially received as view coordinates that you need to map to the scene in order to interact with the project.
Coordinate mapping
When working with projects in a scene, can usually map coordinates and arbitrary shapes from the scene to the project, from the project to the project, or from the view to the scene. For example, when you click the mouse in the QGraphicsView viewport, you can ask about the item under the scene cursor by calling QGraphicsView::mapToScene () and then QGraphicsScene::ItemAt (). If you want to know the location of an item in the viewport, you can call QGraphicsItem::MapToScene () on the item, and then call QGraphicsView::MapFromSecene () on the view. Finally, if you want to find an item in the view ellipse, you can pass QPaineterPath to mapToScene (), and then pass the mapped path to QGraphicScene::items (). can map coordinates and shapes to or from the scene of an item by calling QGraphicsItem::MapToScene () and QGraphicsItem::mapFromScene (). You can also map to the parent of an item by calling QGraphicsItem::mapTopParent () and qgraphicsItem::mapFromParent (), or between items by calling QGraphicsItem::MapToItem () and QGraphicsItem::mapFromItem (). All mapping functions can map points, rectangles, polygons, and paths. There are the same mapping functions in the view that can be used to map to or from a scene. QGraphicsView::mapFromSecene () and QGraphicsView::mapToScene (). To map from a view to a project, first to the scene, and then from the scene to the project.
Key feature scaling and rotation
QGraphicsView supports the same affine transformations that QPainer does through QGraphicsView::setMatrix (). By applying transformations to views, you can easily add support for common navigation features such as zooming and rotation. The following is an example of how to scale and rotate slots in the QGraphicsView subclass:
Class View: public QGraphicsView {Q_OBJECT... public slots: void zoomIn () {scale (1.2,1.2);} void zoomOut () {scale (1 / 1.2,1 / 1.2);} void rotateLeft () {rotate (- 10);} void rotateRight () {rotate (10);}.}
The slot function can be connected to a QToolButtons with automatic repetition enabled. When changes views, QGraphicsView maintains view center alignment. code on how to implement basic scaling, which will be described by examples later.
Project team
By making one project a child of another, enables you to implement the most basic features of project grouping:
The project will be moved together
All transformations propagate from the parent project to the child project.
in addition, QGraphicsItemGroup is a special item that combines subevent handling with a useful interface for adding and removing items to a group. Adding an item to the QGraphicsItemGroup retains the original location and transformation of the item, while typically resetting the item will cause the child item to reposition itself relative to its new parent. For convenience, you can create a QGraphicsItemGroups from the scene by calling QGraphicScene::CreateItemGroup ().
Widgets and layouts
Qt4.4 introduces support for geometry and layout awareness through QGraphicsWidget. This special base entry is similar to QWidget, but unlike QWidget, it inherits not from QPaintDevice, but from QGraphicsItem. This allows you to write complete widgets with events, signals and slots, size tips, and policies, and to manage the geometry of the widgets in the layout through QGraphicsLinearLayout and QGraphicsGridLayout.
QGraphicsWidget
Based on the functionality of QGraphicsItem and its compact footprint, QGraphicsWidget provides the best in two areas: the additional features of QWidget, such as styles, fonts, palettes, layout orientation and its geometry, and the resolution independence and conversion support of QGraphicsItem. Because the graphical view uses real coordinates instead of integers, QGraphicsWidget's geometric functions also run on QRectF and QPointF. This also applies to frame rectangles, margins, and spacing. For example, for QGraphicsWidget, it is not uncommon to specify content margins (0.5,0.5,0.5,0.5). You can create child windows and "top-level" windows; in some cases, you can now use graphical views for advanced MDI applications. some QWidget properties are supported, including window flags and properties, but not all. Refer to QGraphicsWidget's class documentation for a comprehensive understanding of what is supported and what is not. For example, you can create a decorated window by passing the Qt::window flag to the constructor of QGraphicsWidget, but the graphical view currently does not support the Qt::Sheet and Qt:: Drawer flags that are common on MacOs.
QGraphicsLayout
QGraphicsLayout is part of a second-generation layout framework designed specifically for QGraphicsWidget. Its API is very similar to QLayout. You can manage widgets and sublayouts in QGraphicsLinearLayout and QGraphicsGridLayout. You can also easily write your own layout by subclassing QGraphicsLayout yourself, or you can add your own QGraphicsItem items to the layout by writing adaptor subclasses of QGraphicsLayoutItem.
Embedded widget support
The graphical view provides seamless support for embedding any widget in the scene. You can embed simple widgets such as QLineEdit or QPushButton, complex widgets such as QTabWidget, or even a complete main window. To embed the widget into the scene, simply call QGraphicScene::AddWidget (), or create a QGraphicsProxyWidget instance to manually embed the widget. Through QGraphicsProxyWidget, enables graphical views to deeply integrate the functions of client-side widgets, including their cursors, tooltips, mouse, tablet and keyboard events, child widgets, animations, pop-up windows (such as QComboBox or QCompeter), and input focus and activation of widgets. QGraphicsProxyWidget even integrates the tab order of embedded widgets so that you can insert and remove tabs in embedded widgets. You can even embed a new QGraphicsView into your scene to provide a complex nested scene. when converting embedded widgets, the graphical view ensures that the widget converts resolution independently, allowing fonts and styles to remain clear when zoomed in. (note that the effect of resolution independence depends on the style.)
Performance floating point instruction
In order to apply the transformation and effect to the project accurately and quickly, constructs a graphical view on the assumption that the user's hardware can provide reasonable performance for floating-point instructions. many workstations and desktops are equipped with appropriate hardware to speed up this calculation, but some embedded devices may only provide libraries to handle mathematical operations or floating-point instructions in simulation software. therefore, some types of effects may be slower than expected on some devices. You can compensate for this performance loss by optimizing in other areas; for example, rendering a scene using OpenGL. However, if these optimizations also depend on the presence of floating-point hardware, they may themselves lead to performance degradation.
At this point, I believe you have a deeper understanding of "what is the Qt graphical view framework". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.