简体   繁体   English

如何在轮子事件QGraphicsView Qt C ++上禁用滚动功能

[英]How to disable scrolling functionality on wheel event QGraphicsView Qt C++

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. 我已经删除了滚动条但鼠标滚轮仍然会滚动,甚至滚动显示在qGraphicsView显示的图像,显​​示空白(白色)空间,而我的手拖动不会。

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 安装eventfilter并过滤

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. 编辑:我认为它应该适用于QEvent :: GraphicsSceneWheel。 If anyone knows why works with Wheel, please, explain 如果有人知道为什么使用Wheel,请解释

Also, you can to modify QGraphicsView using inheritance 此外,您可以使用继承来修改QGraphicsView

class MyCustomGraphicsView : public QGraphicsView
{

virtual void    wheelEvent ( QWheelEvent * event )
{
//here you can modify wheel-event
}

}

It is easy way, because qt-designer can associate GraphicsView element on your form with your inherited class 这很简单,因为qt-designer可以将表单上的GraphicsView元素与继承的类相关联

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM