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

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

        <tfoot id='2i7YY'></tfoot>
      1. <small id='2i7YY'></small><noframes id='2i7YY'>

          <bdo id='2i7YY'></bdo><ul id='2i7YY'></ul>

        如何在 PyQt5 中從鼠標到點畫一條線?

        How to draw a line from mouse to a point in PyQt5?(如何在 PyQt5 中從鼠標到點畫一條線?)
        <legend id='YT7bp'><style id='YT7bp'><dir id='YT7bp'><q id='YT7bp'></q></dir></style></legend>
        <i id='YT7bp'><tr id='YT7bp'><dt id='YT7bp'><q id='YT7bp'><span id='YT7bp'><b id='YT7bp'><form id='YT7bp'><ins id='YT7bp'></ins><ul id='YT7bp'></ul><sub id='YT7bp'></sub></form><legend id='YT7bp'></legend><bdo id='YT7bp'><pre id='YT7bp'><center id='YT7bp'></center></pre></bdo></b><th id='YT7bp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='YT7bp'><tfoot id='YT7bp'></tfoot><dl id='YT7bp'><fieldset id='YT7bp'></fieldset></dl></div>

              <tfoot id='YT7bp'></tfoot>
                • <bdo id='YT7bp'></bdo><ul id='YT7bp'></ul>

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

                    <tbody id='YT7bp'></tbody>
                  本文介紹了如何在 PyQt5 中從鼠標到點畫一條線?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  這是我的代碼:

                  import sys
                  from PyQt5.QtWidgets import (QApplication, QLabel, QWidget)
                  from PyQt5.QtGui import QPainter, QColor, QPen
                  from PyQt5.QtCore import Qt
                  
                  class MouseTracker(QWidget):
                      distance_from_center = 0
                      def __init__(self):
                          super().__init__()
                          self.initUI()
                          self.setMouseTracking(True)
                  
                      def initUI(self):
                          self.setGeometry(200, 200, 1000, 500)
                          self.setWindowTitle('Mouse Tracker')
                          self.label = QLabel(self)
                          self.label.resize(500, 40)
                          self.show()
                  
                      def mouseMoveEvent(self, event):
                          distance_from_center = round(((event.y() - 250)**2 + (event.x() - 500)**2)**0.5)
                          self.label.setText('Coordinates: ( %d : %d )' % (event.x(), event.y()) + "Distance from center: " + str(distance_from_center))       
                  
                          q = QPainter()  #Painting the line
                          q.begin(self)
                          q.drawLine(event.x(), event.y(), 250, 500)
                          q.end()
                  
                      def drawPoints(self, qp, x, y):
                          qp.setPen(Qt.red)
                          qp.drawPoint(x, y)
                  
                  app = QApplication(sys.argv)
                  ex = MouseTracker()
                  sys.exit(app.exec_())
                  

                  我正在嘗試使用以下方法從鼠標位置到小部件中間繪制一條簡單的線:

                  What I'm trying to do is paint a simple line from the position of the mouse to the middle of the widget using this:

                          q = QPainter()  #Painting the line
                          q.begin(self)
                          q.drawLine(event.x(), event.y(), 250, 500)
                          q.end()
                  

                  但是當我運行它時,看不到任何線條.我需要做什么?

                  But when I run it, no line is visible. What do I need to do?

                  推薦答案

                  你必須實現函數QPaintEvent,在這個函數中你必須畫線,另外你必須調用函數update() 更新繪圖.

                  You must implement the function QPaintEvent, in this function you must draw the line, in addition you must call the function update() to update the drawing.

                  import sys
                  from PyQt5.QtWidgets import (QApplication, QLabel, QWidget)
                  from PyQt5.QtGui import QPainter, QColor, QPen
                  from PyQt5.QtCore import Qt
                  
                  class MouseTracker(QWidget):
                      distance_from_center = 0
                      def __init__(self):
                          super().__init__()
                          self.initUI()
                          self.setMouseTracking(True)
                  
                      def initUI(self):
                          self.setGeometry(200, 200, 1000, 500)
                          self.setWindowTitle('Mouse Tracker')
                          self.label = QLabel(self)
                          self.label.resize(500, 40)
                          self.show()
                          self.pos = None
                  
                      def mouseMoveEvent(self, event):
                          distance_from_center = round(((event.y() - 250)**2 + (event.x() - 500)**2)**0.5)
                          self.label.setText('Coordinates: ( %d : %d )' % (event.x(), event.y()) + "Distance from center: " + str(distance_from_center))       
                          self.pos = event.pos()
                          self.update()
                  
                      def paintEvent(self, event):
                          if self.pos:
                              q = QPainter(self)
                              q.drawLine(self.pos.x(), self.pos.y(), 250, 500)
                  
                  
                  app = QApplication(sys.argv)
                  ex = MouseTracker()
                  sys.exit(app.exec_())
                  

                  輸出:

                  這篇關于如何在 PyQt5 中從鼠標到點畫一條線?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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時顯示進度條?)
                  <legend id='SLbzK'><style id='SLbzK'><dir id='SLbzK'><q id='SLbzK'></q></dir></style></legend>
                    <tbody id='SLbzK'></tbody>

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

                        <tfoot id='SLbzK'></tfoot>

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

                            <bdo id='SLbzK'></bdo><ul id='SLbzK'></ul>
                          • 主站蜘蛛池模板: 久久三级av| 日韩国产精品一区二区三区 | 亚洲精品国产成人 | 91日韩| 给我免费的视频在线观看 | 国产欧美一区二区三区久久手机版 | 亚洲福利电影网 | 成人精品一区亚洲午夜久久久 | 亚洲成人在线网 | 精品国产黄a∨片高清在线 www.一级片 国产欧美日韩综合精品一区二区 | 日韩欧美国产成人一区二区 | 国产一区二区黑人欧美xxxx | 国产一区二区三区免费 | 成人高清视频在线观看 | 久久另类| 亚洲网站在线观看 | 国产精品一二三区 | 欧美成人精品一区二区男人看 | 日韩久久网 | 亚洲福利网 | 成人午夜网 | 成人亚洲性情网站www在线观看 | 午夜免费观看 | 日本成人中文字幕在线观看 | 麻豆视频在线免费观看 | 欧洲精品一区 | 久热m3u8 | 亚洲国产一区二区在线 | 自拍 亚洲 欧美 老师 丝袜 | 九九av| 久久剧场 | 成人在线国产 | 国产一区不卡在线观看 | 欧美精品欧美精品系列 | 国产精品毛片久久久久久 | 亚洲国产精品久久 | 国产精品久久久久久久久久免费看 | 亚洲一区国产 | 亚洲综合视频 | 久久99深爱久久99精品 | 欧美视频在线一区 |