不幸的是,Pyqtgraph 不提供 mouseRelease 信号。
因此,我想修改mouseReleaseEventpyqtgraphsGraphicsScene类中的方法以发出自定义信号。
但是在我下面的示例中, mouseReleaseEvent 函数会根据需要覆盖QWidget父级中的等效方法,而不是 pyqtgraph 中的等效方法。如何解决和更改此方法,或者是否有更简单的方法来检测鼠标按钮释放?
import sys, pyqtgraph
from PyQt5 import QtGui, QtWidgets
class Window(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QWidget.__init__(self)
layout = QtGui.QGridLayout(self)
view = pyqtgraph.GraphicsLayoutWidget()
layout.addWidget(view,0,0)
view.scene().sigMouseClicked.connect(self.OnClick)
def OnClick(self):
print("click") # This works inside the GraphicsLayoutWidget.
def mouseReleaseEvent(self,ev): # This does only work outside the pyqtgraph widget. It overrides the method in QWidget and not in pyqtgraph.GraphicsScene()
print("released ",ev)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
form = Window()
form.show()
sys.exit(app.exec_())
LEATH
相关分类