Hello,
I've a class Scene extending QGraphicsSceneand to catch click mouse i'm using the function mousePressEvent ( QGraphicsSceneMouseEvent* event ). This function is coded like:
// set local variables and check if existing station clicked
qreal x = event->scenePos().x();
qreal y = event->scenePos().y();
GraphItem _item = dynamic_cast<GraphItem*> ( itemAt ( x, y ) );
if ( GraphItem == 0 && event->button() == Qt::LeftButton ) {
m_undoStack->push ( new CommandGraphItemAdd ( this, x, y ) );
emit message
( QString ( "GraphItem add at %1,%2" ).
arg ( x
).
arg ( y
) );
}
this->update();
}
void Scene::mousePressEvent ( QGraphicsSceneMouseEvent* event ) {
// set local variables and check if existing station clicked
qreal x = event->scenePos().x();
qreal y = event->scenePos().y();
GraphItem _item = dynamic_cast<GraphItem*> ( itemAt ( x, y ) );
if ( GraphItem == 0 && event->button() == Qt::LeftButton ) {
m_undoStack->push ( new CommandGraphItemAdd ( this, x, y ) );
emit message ( QString ( "GraphItem add at %1,%2" ).arg ( x ).arg ( y ) );
}
QGraphicsScene::mousePressEvent ( event );
this->update();
}
To copy to clipboard, switch view to plain text mode
My problem is how to create various QGraphicItem into the mousePressEvent function ? For example i click a button into menu option and a point is selecting, or a circle or other.
My solution is using a switch that reads a value (for example an int value, it set when a button is clicked), but for me isn't optimal solution. What do you think?Exist any different solution?
tnx so much
Bookmarks