Qt开发GraphicsView编程
一、QGraphicsScene
1、QGraphicsScene
QGraphicsScene继承自QObject,是一个管理图元的容器,与QGraphicsView合用可以在2D屏幕上显示如线、三角形、文本、自定义图元等图元。
QGraphicsScene是不可见的,只用于管理图元。为了查看场景,需要创建一个视图组件。
一个场景分为三个层:图元层、前景层和背景层。场景的绘制总是从背景层开始,然后是图形项层,最后是前景层。
2、事件处理与传播
QGraphicsScene的责任之一是传播来自视图的事件。要发送一个事件到场景,需要构造一个继承自QEvent的事件,使用QApplication::sendEvent()函数发送事件。event()函数负责派发事件到各个图元。常用的事件会被便利事件处理函数处理,如鼠标按下事件会被mousePressEvent()函数处理。
按键事件会被派发到焦点图元。为了设置焦点图元,可以调用setFocusItem()函数,或是图元自身调用QGraphicsItem::setFocus()函数。调用focusItem()函数可以获取当前的焦点图元。为了兼容图形组件,场景维护着自己的焦点信息。默认场景并没有焦点,并且所有的按键事件会被丢弃。如果setFocus()函数被调用,或是场景中一个图元获得了焦点,场景会自动获得焦点。如果场景有焦点,hasFocus()函数会返回true,按键事件会被发送到焦点图元。如果场景失去了焦点,而图元有焦点(如调用clearFocus()函数),场景会维护图元的焦点信息,一旦场景重新获得焦点,会确保最后一个有焦点的图元获得焦点。
对于悬停效果,QGraphicsScene会派发悬停事件,如果某个图元接受了悬停事件(调用QGraphicsItem::acceptHoverEvents()),当鼠标进入图元的区域时,图元会接收到一个GraphicsSceneHoverEnter事件。当鼠标继续在图元内部移动时,QGraphicsScene会发送GraphicsSceneHoverMove事件。当鼠标离开图元的区域时,图元会收到一个GraphicsSceneHoverLeave事件。
所有鼠标事件会被传播到当前鼠标获取的图元。如果一个图元接收了鼠标事件,并收到鼠标按下,图元就是场景的鼠标获取图元。这个图元会一直被鼠标获取,直到图元收到一个鼠标释放事件。调用mouseGrabberItem()函数可以知道当前鼠标获取的图元。
场景可以传递来自视图的事件,将事件传递给该点最顶层的图元。如果一个图元要接收键盘事件,那么它必须获得焦点。而且,如果在场景中重写了事件处理函数,那么在该函数的最后必须调用场景默认的事件处理函数,只有这样,图元才能接收到该事件。
A、拖拽事件〔virtualprotected〕voiddragEnterEvent(QGraphicsSceneDragDropEventevent)
拖入事件处理函数〔virtualprotected〕voiddragLeaveEvent(QGraphicsSceneDragDropEventevent)
拖离事件梳理函数〔virtualprotected〕voiddragMoveEvent(QGraphicsSceneDragDropEventevent)
拖动事件处理函数〔virtualprotected〕voiddropEvent(QGraphicsSceneDragDropEventevent)
Drop事件处理函数
在以上拖拽事件处理函数中的末尾需要调用QGraphicsScene类相应的事件处理函数。QGraphicsScene::dragEnterEvent(event);QGraphicsScene::dragLeaveEvent(event);QGraphicsScene::dragMoveEvent(event);QGraphicsScene::dropEvent(event);
B、鼠标事件〔virtualprotected〕voidmouseMoveEvent(QGraphicsSceneMouseEventmouseEvent)
鼠标移动处理函数〔virtualprotected〕voidmousePressEvent(QGraphicsSceneMouseEventmouseEvent)
鼠标按下处理函数〔virtualprotected〕voidmouseReleaseEvent(QGraphicsSceneMouseEventmouseEvent)
鼠标释放处理函数
在以上鼠标事件处理函数中的末尾需要调用QGraphicsScene类相应的事件处理函数。QGraphicsScene::mouseMoveEvent(event);QGraphicsScene::mousePressEvent(event);QGraphicsScene::mouseReleaseEvent(event);
3、索引算法
索引算法,是指在场景中进行图元查找的算法。QGraphicsScene中提供了两种选择,在一个枚举变量QGraphicsScene::ItemIndexMethod中定义,分别是:
QGraphicsSecne::BspTreeIndex:应用BinarySpacePartitiontree,适合于大量的静态图元,是默认值。
QGraphicsScene::NoIndex:不用索引,搜索场景中所有的图元,适合于经常进行图元的添加、移动和删除等操作的情况。
使用setItemIndexMethod()函数进行索引算法的更改。
4、边界矩形
图元可以放到场景的任何位置,场景的大小默认是没有限制的。而场景的边界矩形仅用于场景内部进行索引的维护。因为如果没有边界矩形,场景就要搜索所有的图元,然后确定出其边界,这是十分费时的。所以如果要操作一个较大的场景,应该给出它的边界矩形。
设置边界矩形,可以使用setSceneRect()函数。
5、图元的查找
场景最大的优势之一就是可以快速的锁定图元的位置,即使有上百万个图元,items()函数也能在数毫秒的时间内锁定一个图元的位置。items()函数有几个重载函数来方便的进行图元的查找。如果在场景的一个点可能重叠着几个图元,可以使用itemAt()函数返回最上面的一个图元。
二、QGraphicsItem
1、自定义QGraphicsItem
QGraphicsItem是图元的基类。
自定义图元,首先应该继承QGraphicsItem,然后重写他的两个纯虚公共函数boundingRect()和paint(),boundingRect()函数返回绘制图元大概的区域,paint()函数用来绘制图元内容。
boundingRect()函数有很多用处,场景在boundingRect()来建立它的图元的index,视图使用boundingRect来剪切可见的图元,在重新绘制图元时候,来决定相互重叠的部分,此外,图元的碰撞检测机制也使用的boundingRect()来提供一个高效的定点,在collidesWithItem()更好的碰撞算法建立在调用函数shape(),shape()函数以QpainterPath类型返回图元的精准的轮廓。
场景不希望图元的boundingRect()和shape()变化,除非该图元被通告,如果想通过一些方法改变图元的形状,首先应该调用QgraphicsScene()来允许场景QgraphicsScene来刷新它的图元记录。
图元没有获得焦点时,事件只能从视图传递到场景,不能传递到图元。清除图元的焦点函数为clearFocus()。
2、绘制
paint()函数被QgrapicsView类调用来绘制图元的内容,图元默认是没有背景或者填充颜色的。在函数中没有被绘制的所有区域都将会发亮,可以调用update()来重绘图元,可以选择传递需要重绘的矩形区域(不是必须的)。取决于图元在视图中是否可见,图元可能会也可能不会重绘,QgraphicsItem里面没有和Qwidget::repaint()函数等价的图元通过视图来绘制,从父类图元开始,然后是图元自身,以上升的栈的顺序,可以通过调用setZValue()设置图元的栈顺序,通过zValue()来测试,具有低zvalues的图元比具有高zvalue的图元先绘制,栈顺序应用于兄弟图元,父类图元总是比子类图元更早绘制。
3、排序
所有的图元都按照一个已经声明的稳定的顺序来绘制,声明的顺序决定了当在场景中点击鼠标时候,哪个图元最先接受鼠标的输入。通常情况下,不需要担心图元排序的问题,因为所有的图元都按照一个在场景中声明的自然的顺序。
在一个栈中,子类图元在父类图元的上面,兄弟图元按照插入场景的顺序来入栈,如果你先添加图元A,然后是图元B,然后是图元C,栈中的顺序从下往上就是A、B、C。可以调用setZvalue()来设置一个图元的相对于另一个图元向上、向下或者兄弟栈顺序。默认的Z值是0,具有同样的Z值的图元会按照插入的顺序来入栈。可以调用stackBefore()来备份子类图元的列表,直接更正图元的顺序。
如果想让子类图元在父类图元的后面,也就是先绘制子类图元,然后再绘制父类图元。可以利用函数setFlag()设置ItemStacksBehindParent属性给图元。
4、事件处理
QgraphicsItem从场景中通过sceneEvent()函数来接受事件,sceneEvent()函数通过一些方便的操作分散大部分事件。
ContextMenuEvent()函数接受上下文菜单事件,
FocusInEvent()和focusOutEvent()函数接受焦点进出事件,
hoverEnterEvent()、hoverMoveEvent()、hoverLeaveEvent()接受鼠标悬浮移动和离开事件。
inputMethodEvent()函数处理输入法事件,
keyPressEvent()和keyReleaseEvent()事件处理键盘按下和释放事件
mousePressEvent()、mouseMoveEvent()、mouseReleaseEvent()、mouseDoubleClickEvent()处理鼠标按下、移动、释放、双击事件
通过安装过滤器,可以为图元过滤一些事件,与QT一般的事件过滤器不一样,一般的过滤器只工作在Qobject及其子类。通过调用installSceneEventFilter()为图元安装事件过滤器后,被过滤的事件将会被虚函数sceneEventFilter()捕捉到,可以通过调用函数removeSceneEventFilter()来去除掉事件过滤器。
A、拖拽事件
GraphicsView框架为视图、场景、图元提供拖拽支持。当视图接收到拖拽事件,GraphicsView框架会将拖拽事件翻译为QGraphicsSceneDragDropEvent事件,再发送到场景,场景接管事件,把事件发送到光标下接受拖拽的第一个图元。
从图元开始拖拽时,创建一个QDrag对象,传递开始拖拽的QWidget的指针。图元可以同时被多个视图观察,但只有一个视图可以开始拖拽。拖拽在多数情况下是从按下鼠标或是移动鼠标开始的,在mousePressEvent()或mouseMoveEvent()中,可以从事件中得到原始的QWidget指针。
要在场景中取拖拽事件,需要重新实现QGraphicsScene::dragEnterEvent()和QGraphicsItem子类里任何与特定场景需要的事件处理器。图元也可以通过调用QGraphicsItem::setAcceptDrops()获得拖拽支持,为了处理将要进行的拖拽,需要重新实现QGraphicsItem的dragEnterEvent()、dragMoveEvent()、dropEvent()、dragLeaveEvent()。〔virtualprotected〕voiddragEnterEvent(QGraphicsSceneDragDropEventevent)〔virtualprotected〕voiddragLeaveEvent(QGraphicsSceneDragDropEventevent)〔virtualprotected〕voiddragMoveEvent(QGraphicsSceneDragDropEventevent)
〔virtualprotected〕voiddropEvent(QGraphicsSceneDragDropEventevent)
B、鼠标事件
要在自定义图元类中处理鼠标事件,需要重写QGraphicsItem类中鼠标按下、鼠标移动、鼠标释放的事件。〔virtualprotected〕voidmouseMoveEvent(QGraphicsSceneMouseEventevent)〔virtualprotected〕voidmousePressEvent(QGraphicsSceneMouseEventevent)〔virtualprotected〕voidmouseReleaseEvent(QGraphicsSceneMouseEventevent)
5、动画效果
实现图元的动画效果,也可以在不同的层面进行。如果只想控制一两个图元的动画,一般在场景或视图中实现。但是要是想让一个图元类的多个对象都进行同样的动画,那么我们就可以在图元类的构造函数中进行实现。
图元可获得焦点setFlag(QGraphicsItem::ItemIsFocusable);
图元可移动setFlag(QGraphicsItem::ItemIsMovable);QGraphicsItemAnimationanimnewQGraphicsItemAnimation;
将图元加入动画对象中animsetItem(this);
创建长为1秒的时间线QTimeLinetimeLinenewQTimeLine(1000);
动画循环次数为0,表示无限循环timeLinesetLoopCount(0);
将时间线加入动画类对象中animsetTimeLine(timeLine);
在动画时间的一半时图形项旋转180度animsetRotationAt(0。5,180);
在动画执行完时图形项旋转360度animsetRotationAt(1,360);
开始动画timeLinestart();
6、移动
图元的移动,有多种方法实现,可以在视图或场景上控制,但对于不同类型的大量图元,怎样能一起控制呢?在图形视图框架中提供了advance()槽函数,advance()函数在QGraphicsScene和QGraphicsItem中都有定义,在图元类中的原型是advance(intphase)。实现流程是,利用QGraphicsScene类的对象调用QGraphicsScene的advance()函数,会执行两次场景中所有图元的advance(intphase)函数,第一次phase为0,告诉所有图形项即将要移动;第二次phase的值为1,执行移动。QTimertimer;QObject::connect(timer,SIGNAL(timeout()),scene,SLOT(advance()));timer。start(1000);
至于图元如何移动,需要重写图元类的advance()函数。
如果在自定义图元类的构造函数中设置为可移动,则图元可以直接使用鼠标拖拽。setFlag(QGraphicsItem::ItemIsMovable);
7、图元的坐标转换
QgraphicsItem支持坐标转换,对于简单的转换,可以调用函数setRotation()或者setScale(),可以传递一个转换矩阵给函数setTransform(),对于一些更复杂的转换,可以通过调用函数setTransformations()来设置一系列组合的转换。
图元转换从父类到子类进行聚集,因此如果一个父类图元和子类图元都旋转90度,那么子类图元就旋转了180度;如果父类图元和子类图元都放大了2X倍,那么子类图元就被放大4X倍,图元的转换不影响图元的外观,所有和外观有关的函数(例如contains(),update()和所有的映射mapping函数)将会在本地坐标中操作,QgraphicsItem提供函数sceneTransform(),将会返回图元所有的转换矩阵,scenePos()将会返回图元在场景坐标中的位置,重新设置图元的矩阵,调用函数resetTransform()。
一般的转换回产生一个不同的结果,取决于转换应用的顺序,转换顺序不同得到结果将不同。
8、主要成员函数QVariantitemChange(GraphicsItemChangechange,constQVariantvalue)
itemChange函数被QGraphicsItem调用用来标识图元的状态改变了,通过重载itemChange函数,可以对自己定义事件响应。参数change是改变的图元的改变状态参数,value是一个新的数据,类型取决于change,change是QGraphicsItem::GraphicsItemChange枚举变量。
在itemChange函数内部调用函数时候要谨慎,不能在itemChange函数里面调用setPos(),参数change是ItemPositionChange时,setPos()函数将会再次调用itemChange(ItemPositionChange),形成死循环。voidsetFlag(GraphicsItemFlagflag,boolenabledtrue)voidsetFlags(GraphicsItemFlagsflags)
flags设置为图元的属性,如果图元获得了光标,但flags没有使能ItemsFocusable,图元将会丢失光标,当图元被选择,但没有使能ItemsSelectable,图元会自动的失去选择。QPainterPathshape()const
以QPainterPath返回图元在本地坐标中的形状,形状可以用来做很多事情,包括碰撞侦测,打击测试,还有用来QGraphicsScene::items()函数
默认的函数调用boundingRect()返回一个简单的矩形形状,子类可以重载boundingRect函数,为非矩形的图元返回一个更加精准的形状,例如一个圆形的图元可以选择返回一个椭圆形,用来获得更好的碰撞侦测效果。
三、QGraphicsView
1、QGraphicsView简介
QGraphicsView继承自QAbstractScrollArea,继承了QWidget的特性。
QGraphicsView提供了视图窗口部件,使场景的内容可视化。可以给一个场景关联多个视图,从而给一个数据集提供多个视口。视图部件是一个滚动区域,可以提供一个滚动条来显示大型的场景。
2、事件处理
在图形视图框架中,鼠标键盘等事件是从视图进入的,视图将事件传递给场景,场景再将事件传递给该点的图元,如果该点有多个图元,那么就传给最上面的图元。为了使事件能进一步传播到场景,需要在重新实现事件处理函数时,在其最后将event参数传给默认的事件处理函数。比如重写了视图的鼠标按下事件处理函数,那么就在该函数的最后写上QGraphicsView::mousePressEvent(event);
A、拖拽事件
在QGraphicView中提供了三种拖拽模式,分别是:
QGraphicsView::NoDrag:忽略鼠标事件,不可以拖动。
QGraphicsView::ScrollHandDrag:光标变为手型,可以拖动场景进行移动。
QGraphicsView::RubberBandDrag:使用橡皮筋效果,进行区域选择,可以选中一个区域内的所有图元。
可以利用setDragMode()函数进行相应设置。〔virtualprotected〕voiddragEnterEvent(QDragEnterEventevent)〔virtualprotected〕voiddragLeaveEvent(QDragLeaveEventevent)〔virtualprotected〕voiddragMoveEvent(QDragMoveEventevent)〔virtualprotected〕voiddropEvent(QDropEventevent)
在以上拖拽事件处理函数中的末尾需要调用QGraphicsView类相应的事件处理函数。QGraphicsView::dragEnterEvent(event);QGraphicsView::dragLeaveEvent(event);QGraphicsView::dragMoveEvent(event);QGraphicsView::dropEvent(event);
B、鼠标事件〔virtualprotected〕voidmouseMoveEvent(QMouseEventevent)〔virtualprotected〕voidmousePressEvent(QMouseEventevent)〔virtualprotected〕voidmouseReleaseEvent(QMouseEventevent)voidsetMouseTracking(boolenable)
在以上鼠标事件处理函数中的末尾需要调用QGraphicsView类相应的事件处理函数。QGraphicsView::mouseMoveEvent(event);QGraphicsView::mousePressEvent(event);QGraphicsView::mouseReleaseEvent(event);
四、程序实例
1、自定义视图
CustomView。h文件:ifndefCUSTOMVIEWHdefineCUSTOMVIEWHincludeQGraphicsViewclassCustomView:publicQGraphicsView{QOBJECTpublic:CustomView(QWidgetparent0);protected:voidmousePressEvent(QMouseEventevent)QDECLOVERRIDE;voidmouseMoveEvent(QMouseEventevent)QDECLOVERRIDE;voidmouseReleaseEvent(QMouseEventevent)QDECLOVERRIDE;voidpaintEvent(QPaintEventevent)QDECLOVERRIDE;voiddragEnterEvent(QDragEnterEventevent)QDECLOVERRIDE;voiddragLeaveEvent(QDragLeaveEventevent)QDECLOVERRIDE;voiddragMoveEvent(QDragMoveEventevent)QDECLOVERRIDE;voiddropEvent(QDropEventevent)QDECLOVERRIDE;};endifCUSTOMVIEWH
CustomView。cpp文件:includeCustomView。hincludeQDebugCustomView::CustomView(QWidgetparent):QGraphicsView(parent){}voidCustomView::mousePressEvent(QMouseEventevent){qDebug()CustomView::mousePressEvent;QGraphicsView::mousePressEvent(event);}voidCustomView::mouseMoveEvent(QMouseEventevent){qDebug()CustomView::mouseMoveEvent;QGraphicsView::mouseMoveEvent(event);}voidCustomView::mouseReleaseEvent(QMouseEventevent){qDebug()CustomView::mouseReleaseEvent;QGraphicsView::mouseReleaseEvent(event);}voidCustomView::paintEvent(QPaintEventevent){qDebug()CustomView::paintEvent;QGraphicsView::paintEvent(event);}voidCustomView::dragEnterEvent(QDragEnterEventevent){qDebug()CustomView::dragEnterEvent;QGraphicsView::dragEnterEvent(event);}voidCustomView::dragLeaveEvent(QDragLeaveEventevent){qDebug()CustomView::dragLeaveEvent;QGraphicsView::dragLeaveEvent(event);}voidCustomView::dragMoveEvent(QDragMoveEventevent){setCursor(Qt::CrossCursor);qDebug()CustomView::dragMoveEvent;QGraphicsView::dragMoveEvent(event);}voidCustomView::dropEvent(QDropEventevent){qDebug()CustomView::dropEvent;QGraphicsView::dropEvent(event);}
2、自定义场景
CustomScene。h文件:ifndefCUSTOMSCENEHdefineCUSTOMSCENEHincludeQGraphicsSceneincludeQGraphicsSceneMouseEventincludeQPaintEventclassCustomScene:publicQGraphicsScene{QOBJECTpublic:CustomScene(QObjectparent0);protected:voidmousePressEvent(QGraphicsSceneMouseEventevent)QDECLOVERRIDE;voidmouseReleaseEvent(QGraphicsSceneMouseEventevent)QDECLOVERRIDE;voidmouseMoveEvent(QGraphicsSceneMouseEventevent)QDECLOVERRIDE;voiddragEnterEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;voiddragLeaveEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;voiddragMoveEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;voiddropEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;};endifCUSTOMSCENEH
点击领取Qt学习资料视频教程链接
CustomScene。cpp文件:includeCustomScene。hincludeQDebugCustomScene::CustomScene(QObjectparent):QGraphicsScene(parent){}voidCustomScene::mousePressEvent(QGraphicsSceneMouseEventevent){qDebug()CustomScene::mousePressEvent;QGraphicsScene::mousePressEvent(event);}voidCustomScene::mouseReleaseEvent(QGraphicsSceneMouseEventevent){qDebug()CustomScene::mouseReleaseEvent;QGraphicsScene::mouseReleaseEvent(event);}voidCustomScene::mouseMoveEvent(QGraphicsSceneMouseEventevent){qDebug()CustomScene::mouseMoveEvent;QGraphicsScene::mouseMoveEvent(event);}voidCustomScene::dragEnterEvent(QGraphicsSceneDragDropEventevent){qDebug()CustomScene::dragEnterEvent;QGraphicsScene::dragEnterEvent(event);}voidCustomScene::dragLeaveEvent(QGraphicsSceneDragDropEventevent){qDebug()CustomScene::dragLeaveEvent;QGraphicsScene::dragLeaveEvent(event);}voidCustomScene::dragMoveEvent(QGraphicsSceneDragDropEventevent){qDebug()CustomScene::dragMoveEvent;QGraphicsScene::dragMoveEvent(event);}voidCustomScene::dropEvent(QGraphicsSceneDragDropEventevent){qDebug()CustomScene::dropEvent;QGraphicsScene::dropEvent(event);}
3、自定义图元
CustomItem。h文件:ifndefCUSTOMITEMHdefineCUSTOMITEMHincludeQGraphicsItemincludeQGraphicsSceneMouseEventclassCustomItem:publicQGraphicsItem{public:CustomItem();voidpaint(QPainterpainter,constQStyleOptionGraphicsItemoption,QWidgetwidget)QDECLOVERRIDE;QRectFboundingRect()constQDECLOVERRIDE;protected:鼠标事件voidmousePressEvent(QGraphicsSceneMouseEventevent)QDECLOVERRIDE;voidmouseMoveEvent(QGraphicsSceneMouseEventevent)QDECLOVERRIDE;voidmouseReleaseEvent(QGraphicsSceneMouseEventevent)QDECLOVERRIDE;拖拽事件voiddragEnterEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;voiddragLeaveEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;voiddragMoveEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;voiddropEvent(QGraphicsSceneDragDropEventevent)QDECLOVERRIDE;private:QColorcolor;};endifCUSTOMITEMH
点击领取Qt学习资料视频教程链接
CustomItem。cpp文件:includeCustomItem。hincludeQDebugincludeQPainterincludeQCursorincludeQPenCustomItem::CustomItem(){colorQt::red;setFlag(QGraphicsItem::ItemIsFocusable);设置图元为可移动的setFlag(QGraphicsItem::ItemIsMovable);setAcceptDrops(true);}voidCustomItem::paint(QPainterpainter,constQStyleOptionGraphicsItemoption,QWidgetwidget){QUNUSED(option);QUNUSED(widget);qDebug()CustomItem::paint;if(hasFocus()){paintersetPen(QPen(QColor(255,255,255,200)));}else{paintersetPen(QPen(QColor(100,100,100,100)));}paintersetBrush(color);painterdrawRect(10,10,20,20);}QRectFCustomItem::boundingRect()const{qrealadjust0。5;returnQRectF(10adjust,10adjust,20adjust,20adjust);}voidCustomItem::mousePressEvent(QGraphicsSceneMouseEventevent){QUNUSED(event);qDebug()CustomItem::mousePressEvent;setCursor(Qt::OpenHandCursor);}voidCustomItem::mouseMoveEvent(QGraphicsSceneMouseEventevent){setCursor(Qt::DragMoveCursor);qDebug()CustomItem::mouseMoveEvent;}voidCustomItem::mouseReleaseEvent(QGraphicsSceneMouseEventevent){qDebug()CustomItem::mouseReleaseEvent;setCursor(Qt::ArrowCursor);}voidCustomItem::dragEnterEvent(QGraphicsSceneDragDropEventevent){setCursor(Qt::CrossCursor);qDebug()CustomItem::dragEnterEvent;}voidCustomItem::dragLeaveEvent(QGraphicsSceneDragDropEventevent){setCursor(Qt::ForbiddenCursor);qDebug()CustomItem::dragLeaveEvent;}voidCustomItem::dragMoveEvent(QGraphicsSceneDragDropEventevent){setCursor(Qt::CrossCursor);qDebug()CustomItem::dragMoveEvent;}voidCustomItem::dropEvent(QGraphicsSceneDragDropEventevent){setCursor(Qt::WaitCursor);qDebug()CustomItem::dropEvent;}
4、程序使用
登录后复制includeCustomScene。hincludeCustomView。hincludeCustomItem。hincludeQApplicationincludeQTimeintmain(intargc,charargv〔〕){QApplicationa(argc,argv);qsrand(QTime(0,0,0)。secsTo(QTime::currentTime()));CustomScenescene;scene。setSceneRect(200,150,400,300);for(inti0;i5;i){CustomItemitemnewCustomItem;itemsetPos(i5090,50);scene。addItem(item);}CustomViewview;view。setScene(scene);view。show();returna。exec();}
白天看见月亮,是我出门太早了吗?白天太阳升起,夜晚月光皎洁,这是我们从记事起就明白的生活常识,但有时候白天一抬头,怎么一边儿是太阳,一边儿是月亮?是我出门太早了吗?曌首先我们都知道,月亮绕着地球公转的同时自转,地
办公网游观影多合一,深度评测搭载R75800H的零刻SER5Pro前言哈喽大家好,我是疯爆银熊,今天跟大家分享一个最近刚入手的Mini电脑零刻SER5Pro,该款Mini电脑搭载了AMDR75800HCPU,准系统版本只要1595元。性价比直接爆
飞凡R7深度对比特斯拉ModelY,谁更适合新手司机?今年年初,我国正式取消了对新能源汽车的补贴政策,这也使得各大新能源汽车厂家进行了价格上的调整。不过特斯拉ModelY却是先降价后涨价,虽然关注度高了,但是这番操作着实让人迷惑。笔者
一个被阉割的中国皇帝在那种年月里,我已不懂得什么叫羞耻。这是溥仪在自传我的前半生里的一句话。于他而言,朕的大清亡了并不是一句讽刺食古不化的戏谑之语,而是如时代的丧钟一般震耳欲聋。作为中国历史上最后一位
脸红心跳!夏花开分7。1,央视推荐,47岁言承旭再演偶像剧本月的荧屏毫无疑问是热闹的,足以称得上是暮春三月,万物生发的热闹。不仅剧集种类繁多,就连剧集质量平均都在水准之上。比如全网讨论度极高,几乎仙侠粉人人都在看的大IP重紫,虽然对于演技
打打游戏就能考职称?电竞选手没那么容易职称考试内容丰富既有实操也有笔试打打游戏就能考职称?电竞选手没那么容易近期,第二批电子竞技员职业技能等级认定考试成绩公布,来自王者荣耀职业联赛(以下简称KPL)的142位选手报考,
定了!与亚马逊游戏签订全球发行合约NCSOFT2月23日表示,与AmazonGames签订了MMORPG新作王权与自由THRONEANDLIBERTY的全球发行合约。AmazonGames透过此次的合约取得了包含T
独行侠大胜马刺!欧文东契奇轰51分,6配角齐爆,防守篮板仍崩北京时间2月24号独行侠和马刺的比赛,这场比赛独行侠打得非常流畅,特别是进攻端,持续保持高效。这也让独行侠全场保持优势,末节一波流之后,直接142116吊打了马刺。这场比赛独行侠和
真搞笑,什么时候黄土高原改成要保护沙漠了?先给你们说说我在网上看到的一个真实笑话,有一对福建情侣去陕北拍婚纱照,从榆林去沙漠的路上看到遍地郁郁葱葱绿意盎然。两人都纳闷了,这是传说中的黄土高原吗?摄影师笑着告诉他们,你们下车
绿镜头摄影师我们在长江网玩得很嗨视频加载中长江网讯(记者王玮琦)从拍摄创作上传分享与网友交流互动,确实是一个快乐享受的过程。2月24日下午,长江网2022年度发布暨成立20周年网友节活动开幕。活动现场,背着各种长
詹宁斯勇士的前景取决于库里的恢复情况这赛季结束追梦会离开直播吧2月24日讯近日,前NBA球员布兰登詹宁斯在GilsArena节目中谈到了勇士。詹宁斯表示勇士的前景取决于库里的恢复情况,我听说他这周或下周会被重新评估,我们看看他什么时候回