键盘事件后的PYQT鼠标事件

时间:2019-02-21 21:14:47

标签: python canvas pyqt mouseevent keyboard-events

我写了这堂课

from matplotlib.backends.backend_qt4agg import FigureCanvasQTAgg as FigureCanvas
import matplotlib.pyplot as plt
from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4 import QtGui


class Canvas(FigureCanvas):
    """
    CLASS used to convert widget into a matplotlib figure
    """
    signal = pyqtSignal()
    def __init__(self, parent=None):
        self.figure = plt.figure()
        FigureCanvas.__init__(self, self.figure)
        FigureCanvas.setSizePolicy( self, QtGui.QSizePolicy.Expanding,QtGui.QSizePolicy.Expanding )
        FigureCanvas.updateGeometry( self )
        self.setParent(parent)
        self.cid = self.figure.canvas.mpl_connect('button_press_event', self)

    def __call__(self, event):

        if event.button == 3:  # right button

            print(event.xdata)
            print(event.ydata)
            return event.xdata, event.ydata

仅返回用户在画布上单击(右键单击)的数据点值

我想改进此类,增加更多事件。 由于所有事件都是鼠标事件,所以只有两个按钮 我希望能够启用一项操作(由鼠标事件触发) 仅在特定的击键之后。

有什么帮助吗?

0 个答案:

没有答案