久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

  1. <legend id='OVx5T'><style id='OVx5T'><dir id='OVx5T'><q id='OVx5T'></q></dir></style></legend>
  2. <i id='OVx5T'><tr id='OVx5T'><dt id='OVx5T'><q id='OVx5T'><span id='OVx5T'><b id='OVx5T'><form id='OVx5T'><ins id='OVx5T'></ins><ul id='OVx5T'></ul><sub id='OVx5T'></sub></form><legend id='OVx5T'></legend><bdo id='OVx5T'><pre id='OVx5T'><center id='OVx5T'></center></pre></bdo></b><th id='OVx5T'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='OVx5T'><tfoot id='OVx5T'></tfoot><dl id='OVx5T'><fieldset id='OVx5T'></fieldset></dl></div>

      <bdo id='OVx5T'></bdo><ul id='OVx5T'></ul>

    1. <tfoot id='OVx5T'></tfoot>

      <small id='OVx5T'></small><noframes id='OVx5T'>

      如何在 QWidget 中的 matplot 畫布上跟蹤鼠標?

      how to track the mouse over the matplot#39;s canvas in QWidget?(如何在 QWidget 中的 matplot 畫布上跟蹤鼠標?)

        • <small id='PWYEN'></small><noframes id='PWYEN'>

            <bdo id='PWYEN'></bdo><ul id='PWYEN'></ul>
            <tfoot id='PWYEN'></tfoot>
          • <i id='PWYEN'><tr id='PWYEN'><dt id='PWYEN'><q id='PWYEN'><span id='PWYEN'><b id='PWYEN'><form id='PWYEN'><ins id='PWYEN'></ins><ul id='PWYEN'></ul><sub id='PWYEN'></sub></form><legend id='PWYEN'></legend><bdo id='PWYEN'><pre id='PWYEN'><center id='PWYEN'></center></pre></bdo></b><th id='PWYEN'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='PWYEN'><tfoot id='PWYEN'></tfoot><dl id='PWYEN'><fieldset id='PWYEN'></fieldset></dl></div>

                  <tbody id='PWYEN'></tbody>

              1. <legend id='PWYEN'><style id='PWYEN'><dir id='PWYEN'><q id='PWYEN'></q></dir></style></legend>
                本文介紹了如何在 QWidget 中的 matplot 畫布上跟蹤鼠標?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                問題描述

                我想實時跟蹤鼠標在 matplot 畫布上的位置.

                I want to track the mouse's position over a matplot's canvas in real-time.

                現在,我構建了一個繼承 Qwidget(像容器一樣)的 MplWidget,然后在它上面構建了一個畫布來顯示繪圖.但是,問題是我只能在除畫布區域之外的填充區域中跟蹤鼠標的位置.

                For now, I built a MplWidget that inherits the Qwidget (act like a container), then built a canvas over it to show the plot. However, the problem is that I can only track the mouse's position in the padding area except for the canvas area.

                由于我的畫布繼承了不是 QWidget 的 matplotlib.figure,因此它沒有 setMouseTracking() 屬性.這樣,如何解決這個問題?

                Since my canvas inherits the matplotlib.figure that is not a QWidget, thus it doesn't have the setMouseTracking() attribute. In this way, how to resolve this issue?

                我發現了一個非常有用的鏈接如何實時返回鼠標坐標?.然而,它也面臨同樣的問題.當鼠標在標簽(文本區域)上時,跟蹤功能似乎被中斷了.

                I found a quite useful link How to return mouse coordinates in realtime?. However, it also suffers the same issue. When the mouse is over the label (text area), the tracking function seems to be interrupted.

                我的這個類的代碼如下所示:

                my code for this class shown here:

                from PyQt5.QtWidgets import *
                
                from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
                
                from matplotlib.figure import Figure
                
                
                class MplWidget(QWidget):
                
                    def __init__(self, parent=None):
                        # QWidget.__init__(self, parent)
                        super(QWidget, self).__init__(parent)
                
                        self.canvas = FigureCanvas(Figure())
                
                        vertical_layout = QVBoxLayout()
                        vertical_layout.addWidget(self.canvas)
                
                        self.canvas.axes = self.canvas.figure.add_subplot(111)
                        self.setLayout(vertical_layout)
                
                        self.setMouseTracking(True)
                
                    def mouseMoveEvent(self, e):
                        text = "x: {0},  y: {1}".format(e.x(), e.y())
                        print(text)
                        super(MplWidget, self).mouseMoveEvent(e)
                
                    def mousePressEvent(self, e):
                        print('click!')
                

                推薦答案

                您已經注意到畫布不是由 Qt 而是由 matplotlib 處理的,因此解決方案是使用該庫提供的事件,如果您查看 文檔 你看到有以下事件:

                As you have noticed the canvas is not handled by Qt but by matplotlib so the solution is to use the events provided by that library, if you review the docs you see that there are the following events:

                事件名稱 類別和描述

                'button_press_event'  MouseEvent - mouse button is pressed
                'button_release_event'    MouseEvent - mouse button is released
                'draw_event'  DrawEvent - canvas draw (but before screen update)
                'key_press_event' KeyEvent - key is pressed
                'key_release_event'   KeyEvent - key is released
                'motion_notify_event' MouseEvent - mouse motion
                'pick_event'  PickEvent - an object in the canvas is selected
                'resize_event'    ResizeEvent - figure canvas is resized
                'scroll_event'    MouseEvent - mouse scroll wheel is rolled
                'figure_enter_event'  LocationEvent - mouse enters a new figure
                'figure_leave_event'  LocationEvent - mouse leaves a figure
                'axes_enter_event'    LocationEvent - mouse enters a new axes
                'axes_leave_event'    LocationEvent - mouse leaves an axes
                

                在您的情況下,您應該使用事件:

                In your case you should use the events:

                • button_press_event
                • button_release_event
                • motion_notify_event

                例子:

                from PyQt5 import QtWidgets
                
                from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
                from matplotlib.figure import Figure
                
                
                class MplWidget(QtWidgets.QWidget):
                    def __init__(self, parent=None):
                        super(MplWidget, self).__init__(parent)
                        self.canvas = FigureCanvas(Figure())
                
                        vertical_layout = QtWidgets.QVBoxLayout(self)
                        vertical_layout.addWidget(self.canvas)
                
                        self.canvas.axes = self.canvas.figure.add_subplot(111)
                
                        self.canvas.mpl_connect("button_press_event", self.on_press)
                        self.canvas.mpl_connect("button_release_event", self.on_release)
                        self.canvas.mpl_connect("motion_notify_event", self.on_move)
                
                    def on_press(self, event):
                        print("press")
                        print("event.xdata", event.xdata)
                        print("event.ydata", event.ydata)
                        print("event.inaxes", event.inaxes)
                        print("x", event.x)
                        print("y", event.y)
                
                    def on_release(self, event):
                        print("release:")
                        print("event.xdata", event.xdata)
                        print("event.ydata", event.ydata)
                        print("event.inaxes", event.inaxes)
                        print("x", event.x)
                        print("y", event.y)
                
                    def on_move(self, event):
                        print("move")
                        print("event.xdata", event.xdata)
                        print("event.ydata", event.ydata)
                        print("event.inaxes", event.inaxes)
                        print("x", event.x)
                        print("y", event.y)
                
                
                if __name__ == "__main__":
                    import sys
                
                    app = QtWidgets.QApplication(sys.argv)
                    w = MplWidget()
                    w.show()
                    sys.exit(app.exec_())
                

                這篇關于如何在 QWidget 中的 matplot 畫布上跟蹤鼠標?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

                【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

                相關文檔推薦

                How to bind a function to an Action from Qt menubar?(如何將函數綁定到 Qt 菜單欄中的操作?)
                PyQt progress jumps to 100% after it starts(PyQt 啟動后進度躍升至 100%)
                How to set yaxis tick label in a fixed position so that when i scroll left or right the yaxis tick label should be visible?(如何將 yaxis 刻度標簽設置在固定位置,以便當我向左或向右滾動時,yaxis 刻度標簽應該可見
                `QImage` constructor has unknown keyword `data`(`QImage` 構造函數有未知關鍵字 `data`)
                Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                • <i id='8RZiB'><tr id='8RZiB'><dt id='8RZiB'><q id='8RZiB'><span id='8RZiB'><b id='8RZiB'><form id='8RZiB'><ins id='8RZiB'></ins><ul id='8RZiB'></ul><sub id='8RZiB'></sub></form><legend id='8RZiB'></legend><bdo id='8RZiB'><pre id='8RZiB'><center id='8RZiB'></center></pre></bdo></b><th id='8RZiB'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='8RZiB'><tfoot id='8RZiB'></tfoot><dl id='8RZiB'><fieldset id='8RZiB'></fieldset></dl></div>
                    <bdo id='8RZiB'></bdo><ul id='8RZiB'></ul>

                    <legend id='8RZiB'><style id='8RZiB'><dir id='8RZiB'><q id='8RZiB'></q></dir></style></legend>
                      <tbody id='8RZiB'></tbody>
                    <tfoot id='8RZiB'></tfoot>

                    <small id='8RZiB'></small><noframes id='8RZiB'>

                        1. 主站蜘蛛池模板: 狠狠亚洲| 日韩成人 | 亚洲最新网址 | 成人黄色av网站 | 国产日韩亚洲欧美 | 亚洲国产欧美国产综合一区 | 国产成人精品一区二 | 国外激情av | www.久草.com| 精品区一区二区 | 福利精品 | 99精品热视频 | 午夜精品一区二区三区免费视频 | 国产在线观 | 亚洲乱码国产乱码精品精的特点 | 日韩精品一区二区三区中文在线 | 久久国产香蕉 | 中文字幕在线观看视频网站 | 成人在线中文字幕 | 日韩美av | 理伦毛片 | 欧美最猛性xxxxx亚洲精品 | 在线国产一区二区三区 | 99成人精品| 免费精品国产 | 中文字幕在线免费观看 | 自拍视频网站 | 中文字幕亚洲欧美日韩在线不卡 | 不卡一区二区三区四区 | 精品伊人久久 | 成人欧美一区二区三区在线观看 | 久久久久国产精品 | 91在线精品秘密一区二区 | 国产一区二区在线免费观看 | 国产片一区二区三区 | 欧美一区二区在线观看 | 欧洲亚洲一区 | 久久精品—区二区三区 | 欧美手机在线 | 青春草在线 | 国产精品高潮呻吟久久av黑人 |