gpt4 book ai didi

python - PyQt QWebPage linkClicked 信号可以检测使用了哪个鼠标按钮

转载 作者:行者123 更新时间:2023-12-01 05:50:58 25 4
gpt4 key购买 nike

我目前正在将此信号与处理点击的函数连接起来。例如:

QtCore.QObject.connect(self.ui.webView, QtCore.SIGNAL("linkClicked (const QUrl&)"), self.navigate)

def navigate(self, url):
#do something

我想要的是导航功能知道是否通过鼠标左键或右键单击了链接。类似的东西

def navigate(self, url, event):
if event == Qt.LeftClick:
#do something
if event == Qt.MidClick:
#do something else

这可能吗?

最佳答案

另一种方法是重新实现 mousePressEvent 并在那里过滤鼠标事件:

#!/usr/bin/env python
#-*- coding:utf-8 -*-

from PyQt4 import QtCore, QtGui

class myWindow(QtGui.QWidget):
def __init__(self, parent=None):
super(myWindow, self).__init__(parent)

self.label = QtGui.QLabel(self)
self.label.setText("Click Me")

self.layout = QtGui.QHBoxLayout(self)
self.layout.addWidget(self.label)


def mousePressEvent(self, event):
if event.buttons() == QtCore.Qt.LeftButton:
self.label.setText("Left Mouse Click!")

elif event.buttons() == QtCore.Qt.RightButton:
self.label.setText("Right Mouse Click!")

return super(myWindow, self).mousePressEvent(event)

if __name__ == "__main__":
import sys

app = QtGui.QApplication(sys.argv)
app.setApplicationName('myWindow')

main = myWindow()
main.resize(150, 150)
main.show()

sys.exit(app.exec_())

关于python - PyQt QWebPage linkClicked 信号可以检测使用了哪个鼠标按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14317328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com