0

全て、

私はとを持ってQGraphicsEllipseItemsetFlags(Qt::ItemIsSelectable | Qt::ItemIsMovable)ます。これにより、QGraphicsViewで省略記号をすばやくドラッグして移動できます。

私は空想にふけり、setCursor(Qt::OpenHandCursor)クリックすることで移動できることをユーザーに知らせることにしました。しかし、マウスの左ボタンを離しても手放せなくなりましたか?私は何が間違っているのですか?


サンプルコード:カスタムQGraphicItemと再描画の問題

注:呼び出しを削除し、update()呼び出しを追加しましprepareGeometryChange()た。MakeNewPoint次に、関数を変更します。

QGraphicsEllipseItem * InteractivePolygon::MakeNewPoint(QPointF & new_point)
{
   QGraphicsEllipseItem * result = 0;
   result = new QGraphicsEllipseItem();
   result->setPos(new_point);
   result->setRect(-4, -4, 8, 8);
   result->setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemIsSelectable)
   result->setCursor(Qt::OpenHandCursor); //Setting this removes my ability to let go of an item. NOTE: result is parented by this.

   return result;
}

後で:

 QGraphicsEllipseItem * new_item = MakeNewPoint(bla);
 new_item->setParent(this);
 //add it to my QList<QGraphicsEllipseItem *> m_points;

QGraphicsEllipseItem私はカスタムによって親になっていることに注意したいと思いますQGraphicsItem。親/カスタムアイテムカーソルは変更せず、楕円のみを変更します。親のない省略記号ではこの問題は発生しません...


Interesting result: So my class custom QGraphicsItem class (the parent of the ellipses) is a QObject so I can filter incoming mouse events from the scene. I did a setCursor(Qt::ArrowCursor) in my custom class's constructor... and here's where it gets interesting:

The eventFilter now catches (event->type() == QEvent::GraphicsSceneMouseMove) even if a mouse button isn't pressed down. If I don't have the setCursor call, that event only fires while a mouse button is pressed... thoughts?

4

1 に答える 1

2

Okay got it, here's what's happening, it's intuitive once you realize it:

When you set that a QGraphicsItem to a unique cursor, the QGraphicsView has to setMouseTracking(true) otherwise the QGraphicsScene will never know when to change the cursor (ie when it's over the graphics item with the unique cursor.) The mouse move events were affecting my ellipse.

Normally, the QGraphicsScene only gets mouse move events when a button is held down.

于 2012-11-08T19:10:18.553 に答える