全て、
私はとを持ってQGraphicsEllipseItem
いsetFlags(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?