As far as I understand you can only add items to a scene not to view, so you need to get the current view's view port and then add the cursor there, this needs to be in your scene, something like this
{
// Get the list of the views attached to this scene
QList<QGraphicsView*> scene_views = views();
for(int i = 0; i < scene_views.count(); i++)
{
// get the visible view port
QWidget* viewport_widget
= scene_views.
at(i
)->viewport
();
// ensure it is visible
if(viewport_widget->isVisible())
{
// Update cursor position (text to be displayed)
.arg(event->scenePos().x())
.arg(event->scenePos().y());
cursor->setPlainText(string);
// Set the new position of the cursor
cursor->setPos(viewport_widget->width() - cursor->boundingRect().width()
,viewport_widget->height() - cursor->boundingRect().height());
}
}
}
void MyGraphicsScene::mouseMoveEvent(QGraphicsSceneMouseEvent* event)
{
// Get the list of the views attached to this scene
QList<QGraphicsView*> scene_views = views();
for(int i = 0; i < scene_views.count(); i++)
{
// get the visible view port
QWidget* viewport_widget = scene_views.at(i)->viewport();
// ensure it is visible
if(viewport_widget->isVisible())
{
// Update cursor position (text to be displayed)
QString string = QString("%1, %2")
.arg(event->scenePos().x())
.arg(event->scenePos().y());
cursor->setPlainText(string);
// Set the new position of the cursor
cursor->setPos(viewport_widget->width() - cursor->boundingRect().width()
,viewport_widget->height() - cursor->boundingRect().height());
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks