Description
I am stuck with this weird behavior where, if I enable rubberband drag, the wheel event doesn't zoom under mouse anymore. It does zooming but irrespective of mouse position. And if I disable other events, then wheelEvent works properly.
Explanation & Answer
QGraphicsView::scale function's behaviour depends on the mouse position. It's performing automatically and internally by QGraphicsView. Since you don't pass mouse position to the scale function, I think QGraphicsView tracks the mouse and remembers the last position on its own.
By reimplementing mouse event handlers you have taken this ability from it. The view can't determine the mouse position anymore because its original handlers aren't called.
Luckily this issue can be easily fixed. You need to call base class implementation before your own:
void MyGraphics::mousePressEvent(QMouseEvent *event) {
QGraphicsView::mousePressEvent(event);
// your implementation goes here
}
It's an example for mousePressEvent but you should add similar statements to all your event handlers unless you need to disable some part of default behavior.
Review
Review
24/7 Homework Help
Stuck on a homework question? Our verified tutors can answer all questions, from basic math to advanced rocket science!
Similar Content
Related Tags
Broke Millennial: Stop Scraping by and Get Your Financial Life Together
by Erin Lowry
The Splendid and The Vile
by Erik Larson
To the Lighthouse
by Virginia Woolf
Murder on the Orient Express
by Agatha Christie
Mrs Dalloway
by Virginia Woolf
Of Mice and Men
by John Steinbeck
1984
by George Orwell
Little Women
by Louisa May Alcott
Where'd You Go Bernadette
by Maria Semple