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();
方法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;
}