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

      <legend id='HEfzL'><style id='HEfzL'><dir id='HEfzL'><q id='HEfzL'></q></dir></style></legend>

      <tfoot id='HEfzL'></tfoot>

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

      1. <small id='HEfzL'></small><noframes id='HEfzL'>

          <bdo id='HEfzL'></bdo><ul id='HEfzL'></ul>
      2. 如何在 PyQt5 中通過拖放來繪制矩形并調整其形狀

        How to draw a rectangle and adjust its shape by drag and drop in PyQt5(如何在 PyQt5 中通過拖放來繪制矩形并調整其形狀)
        <tfoot id='Ywz4B'></tfoot>
          <tbody id='Ywz4B'></tbody>
          <legend id='Ywz4B'><style id='Ywz4B'><dir id='Ywz4B'><q id='Ywz4B'></q></dir></style></legend>
          <i id='Ywz4B'><tr id='Ywz4B'><dt id='Ywz4B'><q id='Ywz4B'><span id='Ywz4B'><b id='Ywz4B'><form id='Ywz4B'><ins id='Ywz4B'></ins><ul id='Ywz4B'></ul><sub id='Ywz4B'></sub></form><legend id='Ywz4B'></legend><bdo id='Ywz4B'><pre id='Ywz4B'><center id='Ywz4B'></center></pre></bdo></b><th id='Ywz4B'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='Ywz4B'><tfoot id='Ywz4B'></tfoot><dl id='Ywz4B'><fieldset id='Ywz4B'></fieldset></dl></div>

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

                  <bdo id='Ywz4B'></bdo><ul id='Ywz4B'></ul>
                  本文介紹了如何在 PyQt5 中通過拖放來繪制矩形并調整其形狀的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我正在嘗試通過拖放在 PyQt5 創建的 GUI 上繪制一個矩形.我設法做到了,但是釋放鼠標左鍵時會繪制矩形.

                  I'm trying to draw a rectangle on GUI created by PyQt5 by drag and drop. I managed to do that, but the rectangle is drawn when the mouse left key is released.

                  我想做的就是這樣link:

                  • 按下鼠標左鍵時,開始繪制矩形.
                  • 拖動時,通過鼠標移動調整矩形形狀.
                  • 松開鼠標左鍵后,確定矩形形狀.

                  我該如何實現呢?提前致謝.

                  How can I implement this? Thanks in advance.

                  這是我的代碼.

                  # -*- coding: utf-8 -*-
                  
                  import sys
                  from PyQt5 import QtWidgets, QtCore
                  from PyQt5.QtGui import QPainter
                  
                  class MyWidget(QtWidgets.QWidget):
                      def __init__(self):
                          super().__init__()
                          self.setGeometry(30,30,600,400)
                          self.pos1 = [0,0]
                          self.pos2 = [0,0]
                          self.show()
                  
                      def paintEvent(self, event):
                          width = self.pos2[0]-self.pos1[0]
                          height = self.pos2[1] - self.pos1[1]     
                  
                          qp = QPainter()
                          qp.begin(self)           
                          qp.drawRect(self.pos1[0], self.pos1[1], width, height)        
                          qp.end()
                  
                      def mousePressEvent(self, event):
                          self.pos1[0], self.pos1[1] = event.pos().x(), event.pos().y()
                          print("clicked")
                  
                      def mouseReleaseEvent(self, event):
                          self.pos2[0], self.pos2[1] = event.pos().x(), event.pos().y()
                          print("released")
                          self.update()
                  
                  if __name__ == '__main__':
                      app = QtWidgets.QApplication(sys.argv)
                      window = MyWidget()
                      window.show()
                      app.aboutToQuit.connect(app.deleteLater)
                      sys.exit(app.exec_())
                  

                  推薦答案

                  你不必使用mouseReleaseEvent函數,而是每次調用的mouseMoveEvent函數鼠標移動了,我修改了代碼讓它更簡單.

                  You do not have to use the mouseReleaseEvent function, but the mouseMoveEvent function that is called each time the mouse is moved, and I have modified the code to make it simpler.

                  class MyWidget(QtWidgets.QWidget):
                      def __init__(self):
                          super().__init__()
                          self.setGeometry(30,30,600,400)
                          self.begin = QtCore.QPoint()
                          self.end = QtCore.QPoint()
                          self.show()
                  
                      def paintEvent(self, event):
                          qp = QtGui.QPainter(self)
                          br = QtGui.QBrush(QtGui.QColor(100, 10, 10, 40))  
                          qp.setBrush(br)   
                          qp.drawRect(QtCore.QRect(self.begin, self.end))       
                  
                      def mousePressEvent(self, event):
                          self.begin = event.pos()
                          self.end = event.pos()
                          self.update()
                  
                      def mouseMoveEvent(self, event):
                          self.end = event.pos()
                          self.update()
                  
                      def mouseReleaseEvent(self, event):
                          self.begin = event.pos()
                          self.end = event.pos()
                          self.update()
                  

                  這篇關于如何在 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時顯示進度條?)
                  1. <tfoot id='sDLnp'></tfoot>
                        <i id='sDLnp'><tr id='sDLnp'><dt id='sDLnp'><q id='sDLnp'><span id='sDLnp'><b id='sDLnp'><form id='sDLnp'><ins id='sDLnp'></ins><ul id='sDLnp'></ul><sub id='sDLnp'></sub></form><legend id='sDLnp'></legend><bdo id='sDLnp'><pre id='sDLnp'><center id='sDLnp'></center></pre></bdo></b><th id='sDLnp'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sDLnp'><tfoot id='sDLnp'></tfoot><dl id='sDLnp'><fieldset id='sDLnp'></fieldset></dl></div>
                          <bdo id='sDLnp'></bdo><ul id='sDLnp'></ul>
                            <tbody id='sDLnp'></tbody>
                          <legend id='sDLnp'><style id='sDLnp'><dir id='sDLnp'><q id='sDLnp'></q></dir></style></legend>

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

                            主站蜘蛛池模板: 欧美精品一区二区三区蜜桃视频 | 免费观看www7722午夜电影 | 日韩成人精品一区 | 亚洲欧美综合 | 超黄毛片 | 狠狠色综合久久婷婷 | 亚洲综合在 | 午夜电影福利 | 亚洲成人av一区二区 | 国产精品完整版 | 午夜视频精品 | 国产美女网站 | 亚洲另类视频 | 欧美精品久久久久 | 亚洲国产精品久久久久秋霞不卡 | 国产三级日本三级 | 成人综合久久 | 天天射影院| 超碰97免费在线 | 嫩草视频在线看 | 久久久久久久综合 | 99久久婷婷国产综合精品首页 | 武道仙尊动漫在线观看 | jizjizjiz中国护士18 | 日韩伦理电影免费在线观看 | 国际精品鲁一鲁一区二区小说 | 久草视频观看 | 成人做爰69片免费观看 | 亚洲一区二区中文字幕 | 91麻豆精品国产91久久久更新资源速度超快 | 亚洲精品乱码8久久久久久日本 | 久在线视频播放免费视频 | 午夜精品91| 女女百合av大片一区二区三区九县 | 成人精品一区二区 | 亚洲九色 | 日韩成人在线观看 | 青娱乐av | 国产欧美精品一区二区色综合朱莉 | 午夜精品久久久久久久久久久久久 | 在线āv视频 |