【问题标题】:Mousewheel detect not work in webview pyside2鼠标滚轮检测在 webview pyside2 中不起作用
【发布时间】:2021-11-17 05:07:59
【问题描述】:

我想获得鼠标滚轮值增量。具有 WHeelEvent(self,event) 功能,但在 webview 为焦点时不起作用

我尝试使用其他布局小部件并且可以正常工作

请问我该怎么做才能在我的网络视图中获取它?

【问题讨论】:

  • 请提供足够的代码,以便其他人更好地理解或重现问题。

标签: python pyside2 mousewheel


【解决方案1】:

QWebEngineView 使用 focusProxy 来处理鼠标事件,因此您应该使用 eventfilter 监听来自该小部件的事件:

from PySide2.QtCore import QEvent, QUrl
from PySide2.QtWidgets import QApplication
from PySide2.QtWebEngineWidgets import QWebEngineView


class WebView(QWebEngineView):
    def __init__(self, parent=None):
        super().__init__(parent)
        # required for the focusProxy to be created
        self.load(QUrl())
        self.focusProxy().installEventFilter(self)

    def eventFilter(self, obj, event):
        if obj is self.focusProxy() and event.type() == QEvent.Type.Wheel:
            print(event.angleDelta())
        return super().eventFilter(obj, event)


def main():
    app = QApplication()

    w = WebView()
    w.load(QUrl("https://stackoverflow.com/"))
    w.resize(640, 480)
    w.show()

    app.exec_()


if __name__ == "__main__":
    main()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多