I am creating the events in the MainWindow.
I have already tried to send the event to the view, but nothing happens again?!
I even set it to setInteractive(true) although it should be enabled by default.
The code is:
void MainWindow::click()
{
click.setAccepted(true);
}
void MainWindow::click()
{
QMouseEvent click(QEvent::MouseButtonPress, QPoint(126,575), Qt::LeftButton, 0, 0);
click.setAccepted(true);
QCoreApplication::sendEvent(m_view, &click);
}
To copy to clipboard, switch view to plain text mode
I am checking incoming events in the scene derived class and there are no QGraphicsSceneMouseEvents, unless I click with the mouse.
These are the scene and view initializations:
m_scene = new MyScene();
m_scene->setSceneRect(0, 0, 600, 600);
m_scene->setBackgroundBrush(Qt::red);
m_view
->setRenderHint
(QPainter::Antialiasing);
m_view
->setViewportUpdateMode
(QGraphicsView::BoundingRectViewportUpdate);
m_view->setInteractive(true);
m_view->show();
m_scene = new MyScene();
m_scene->setSceneRect(0, 0, 600, 600);
m_scene->setItemIndexMethod(QGraphicsScene::NoIndex);
m_scene->setBackgroundBrush(Qt::red);
m_view = new QGraphicsView(m_scene);
m_view->setRenderHint(QPainter::Antialiasing);
m_view->setCacheMode(QGraphicsView::CacheBackground);
m_view->setViewportUpdateMode(QGraphicsView::BoundingRectViewportUpdate);
m_view->setInteractive(true);
m_view->show();
To copy to clipboard, switch view to plain text mode
Bookmarks