I have a graphics view and i have set my own function for scrolling by hand drag when the user presses control and mouse clicks.
I have removed the scroll bars but the mouse wheel will still scroll and even scroll past the image that's being displayed in the qGraphicsView
showing blank (white) space which my hand drag doesn't.
How do i make it so wheel just straight up does nothing at all?
I know there is a function I can just put in my code without a derived class because I asked this once before and got the right answer but the answer was removed and i hadn't saved the code :(
The below code does nothing even close to the expected functionality, on start up I get the mouse still doing something message and then all clicks and wheel events everything just displays that second message ... so yea not working
bool GUI::eventFilter(QObject *object, QEvent *event)
{
if (object == ui->graphicsView && event->type() == QEvent::GraphicsSceneWheel)
{
std::cout << "Wheel Blocked";
return true;
}
std::cout << "Mouse Wheel still doing something";
return false;
}
and then this code to install the filter
ui->graphicsView->installEventFilter(this);
Install an eventfilter and filter for
QEvent::GraphicsSceneWheel
Create something like this in your app
bool MainWindow::eventFilter(QObject *object, QEvent *event)
{
if (object == ui->graphicsView->viewport() && event->type() == QEvent::Wheel) {
qDebug() << "SCroll";
return true;
}
return false;
}
and install to your widget.
yourwidget->viewport()->installEventFilter(this);
Edit: I thought it should work with QEvent::GraphicsSceneWheel. If anyone knows why works with Wheel, please, explain
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With