结合这个demo来学习图形视图框架,肯定效果很好
QApplication app(argc, argv);
app.setAttribute(Qt::AA_DontCreateNativeWidgetSiblings);
Qt::AA_DontCreateNativeWidgetSiblings
4
Ensures that siblings of native widgets stay non-native unless specifically set by the Qt::WA_NativeWindow attribute.
Native:原生的Sibling:兄弟
QSplitter *vSplitter = new QSplitter;
vSplitter->setOrientation(Qt::Vertical);
orientation : Qt::Orientation
orientation:方向
splitter:分裂器
side by side:并排的
This property holds the orientation of the splitter
By default, the orientation is horizontal (i.e., the widgets are laid out side by side). The possible orientations are Qt::Horizontal and Qt::Vertical.
Access functions:
Qt::Orientation
orientation() const
void
setOrientation(Qt::Orientation)
QColor color(image.pixel(int(image.width() * x), int(image.height() * y)));
QRgb QImage::pixel(const QPoint &position) const
pixel:像素
massive:大规模的
manipulation:使用
Returns the color of the pixel at the given position.
If the position is not valid, the results are undefined.
Warning: This function is expensive when used for massive pixel manipulations. Use constBits() or constScanLine() when many pixels needs to be read.
See also setPixel(), valid(), constBits(), constScanLine(), and Pixel Manipulation.
graphicsView->setRenderHint(QPainter::Antialiasing, false);
QPainter::Antialiasing
0x01
Indicates that the engine should antialias edges of primitives if possible.
Antialiasing:抗锯齿antialias:抗锯齿
primitives:图元
edges:边缘
graphicsView->setDragMode(QGraphicsView::RubberBandDrag);
QGraphicsView::RubberBandDrag
2
A rubber band will appear. Dragging the mouse will set the rubber band geometry, and all items covered by the rubber band are selected. This mode is disabled for non-interactive views.rubber:橡胶
band:带状物
geometry:几何图形
graphicsView->setOptimizationFlags(QGraphicsView::DontSavePainterState);
optimizationFlags : OptimizationFlags
optimization:最优化
tune:调整
performance:执行
flags that can be used to tune QGraphicsView's performance.
extra:额外的
bounding:边界框
certain:确定的
aid:帮助
render:绘制
common case:常见情况
degrade:降低
varies:改变
QGraphicsView uses clipping, extra bounding rect adjustments, and certain other aids to improve rendering quality and performance for the common case graphics scene. However, depending on the target platform, the scene, and the viewport in use, some of these operations can degrade performance.
The effect varies from flag to flag; see the OptimizationFlags documentation for details.
By default, no optimization flags are enabled.
This property was introduced in Qt 4.3.
Access functions:
OptimizationFlags
optimizationFlags() const
void
setOptimizationFlags(OptimizationFlags flags)
See also setOptimizationFlag().
enum QGraphicsView::OptimizationFlag
flags QGraphicsView::OptimizationFlagsThis enum describes flags that you can enable to improve rendering performance in QGraphicsView. By default, none of these flags are set. Note that setting a flag usually imposes a side effect, and this effect can vary between paint devices and platforms.
imposes:强制推行
a side effect:副作用
QGraphicsView::DontSavePainterState
0x2
When rendering, QGraphicsView protects the painter state (see QPainter::save()) when rendering the background or foreground, and when rendering each item. This allows you to leave the painter in an altered state (i.e., you can call QPainter::setPen() or QPainter::setBrush() without restoring the state after painting). However, if the items consistently do restore the state, you should enable this flag to prevent QGraphicsView from doing the same.
altered:改变
graphicsView->setViewportUpdateMode(QGraphicsView::SmartViewportUpdate);
enum QGraphicsView::ViewportUpdateMode
This enum describes how QGraphicsView updates its viewport when the scene contents change or are exposed.
expose:显露
QGraphicsView::SmartViewportUpdate
2
QGraphicsView will attempt to find an optimal update mode by analyzing the areas that require a redraw.attempt:尝试
optimal:最佳的
zoomInIcon->setAutoRepeat(true);
autoRepeat : bool
regular:规律的
intervals:间隔
initial:最初的
This property holds whether autoRepeat is enabled
If autoRepeat is enabled, then the pressed(), released(), and clicked() signals are emitted at regular intervals when the button is down. autoRepeat is off by default. The initial delay and the repetition interval are defined in milliseconds by autoRepeatDelay and autoRepeatInterval.
Note: If a button is pressed down by a shortcut key, then auto-repeat is enabled and timed by the system and not by this class. The pressed(), released(), and clicked() signals will be emitted like in the normal case.
Access functions:
bool
autoRepeat() const
void
setAutoRepeat(bool)
kicks in:开始运作
This property holds the initial delay of auto-repetition
If autoRepeat is enabled, then autoRepeatDelay defines the initial delay in milliseconds before auto-repetition kicks in.
This property was introduced in Qt 4.2.
void QAbstractScrollArea::setViewport(QWidget *widget)
viewport:视口,视窗
Sets the viewport to be the given widget. The QAbstractScrollArea will take ownership of the given widget.
If widget is 0, QAbstractScrollArea will assign a new QWidget instance for the viewport.
This function was introduced in Qt 4.2.
[pure virtual] QRectF QGraphicsItem::boundingRect() const
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item's bounding rect. QGraphicsView uses this to determine whether the item requires redrawing.
arbitrary:随心所欲的
Although the item's shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items' transformation.
notifies:通知
imminent:即将发生的
artifacts:史前古器物
Reimplement:重定义
If you want to change the item's bounding rectangle, you must first call prepareGeometryChange(). This notifies the scene of the imminent change, so that it can update its item geometry index; otherwise, the scene will be unaware of the item's new geometry, and the results are undefined (typically, rendering artifacts are left within the view).
Reimplement this function to let QGraphicsView determine what parts of the widget, if any, need to be redrawn.
compensate:补偿
though:不过
Note: For shapes that paint an outline / stroke, it is important to include half the pen width in the bounding rect. It is not necessary to compensate for antialiasing, though.
Example:
QRectF CircleItem::boundingRect() const { qreal penWidth = 1; return QRectF(-radius - penWidth / 2, -radius - penWidth / 2, diameter + penWidth, diameter + penWidth); }
[virtual] QPainterPath QGraphicsItem::shape() const
Returns the shape of this item as a QPainterPath in local coordinates. The shape is used for many things, including collision detection, hit tests, and for the QGraphicsScene::items() functions.
collision detection:碰撞检测
accurate:精确的
round:圆形的
The default implementation calls boundingRect() to return a simple rectangular shape, but subclasses can reimplement this function to return a more accurate shape for non-rectangular items. For example, a round item may choose to return an elliptic shape for better collision detection. For example:
QPainterPath RoundItem::shape() const { QPainterPath path; path.addEllipse(boundingRect()); return path; }
The outline of a shape can vary depending on the width and style of the pen used when drawing. If you want to include this outline in the item's shape, you can create a shape from the stroke using QPainterPathStroker.
This function is called by the default implementations of contains() and collidesWithPath().
collides:碰撞