gif录制软件没有录到鼠标
方法1:通过设置QGraphicsTextItem的属性实现(推荐)
QGraphicsScene scene; QGraphicsTextItem *text = scene.addText("Hello, world!"); //接受鼠标拖动 text->setAcceptHoverEvents(true); text->setFlags(QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemIsMovable); QGraphicsView view(&scene); //鼠标拖动改变位置 view.setDragMode(QGraphicsView::RubberBandDrag); view.show();1
2
3
4
5
6
7
8
9
10
11
方法2:重写鼠标事件
继承QGraphicsItem,重写mousePressEvent、mouseMoveEvent和mouseReleaseEvent三个函数。
void BreakerItem::mousePressEvent( QGraphicsSceneMouseEvent* event )
{
m_mousePressed=true;
m_mousePressedPoint=this->scenePos()-event->scenePos();
}
void BreakerItem::mouseMoveEvent( QGraphicsSceneMouseEvent* event )
{
if(m_mousePressed==true)
{
this->setPos(event->scenePos()+m_mousePressedPoint);
}
} void BreakerItem::mouseReleaseEvent( QGraphicsSceneMouseEvent* event )
{
m_mousePressed=false;
}1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
文章来源: blog.csdn.net,作者:qq_26480033,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/qq_26480033/article/details/112060526