小编SSa*_*bhJ的帖子

如何使用QGraphicsScene的鼠标移动事件?

嘿,想要在按下并移动鼠标按钮时拖动这条贝塞尔曲线.

我这样做了:

void MainWindow::mouseMoveEvent(QMouseEvent *e)
{
qDebug()<<"in mouse move - outside if";
if((e->buttons() & Qt::RightButton) && isStart && enableDrag)
{
    qDebug()<<"mouse dragging happening";
    xc2=e->pos().x();
    yc2=e->pos().y();
    drawDragBezier(xc2,yc2);
}
}
Run Code Online (Sandbox Code Playgroud)

当我按下右键并开始在整个主窗口中移动鼠标时,这开始拖动.但是我只想在我按下鼠标按钮并在QGraphicsScene中移动鼠标时开始拖动.

怎么解决这个?

编辑:

void mySubClass1::mousePressEvent(QGraphicsSceneMouseEvent *event)
{
if(event->button() == Qt::LeftButton)
{
    qDebug()<<"in musubclass mouse press event: "<<event->pos().x()<<" "
<<event- >pos().y();
    if(shape().contains(event->pos()))
    {
        currPosX=event->pos().x();
        currPosY=event->pos().y();
        qDebug()<<"currPosX currPosY: "<<currPosX<<" "<<currPosY;
    }
}
}
Run Code Online (Sandbox Code Playgroud)

主窗口类是:

{
myGPath=new mySubClass1();
myScene=new QGraphicsScene;
myScene->addItem(myGPath);
ui->graphicsView->setScene(myScene);


QPointF *startPoint=new QPointF(50,50);
myPaintPath=new QPainterPath(*startPoint);

myPaintPath->quadTo(100,25,200,200);

myGPath->setPath(*myPaintPath);
}
Run Code Online (Sandbox Code Playgroud)

这是正确的方法吗?

qt mousemove qgraphicsscene

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

mousemove ×1

qgraphicsscene ×1

qt ×1