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

<tfoot id='WEP85'></tfoot>

  • <legend id='WEP85'><style id='WEP85'><dir id='WEP85'><q id='WEP85'></q></dir></style></legend>

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

        • <bdo id='WEP85'></bdo><ul id='WEP85'></ul>

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

      1. 用畫筆畫畫

        Drawing with a brush(用畫筆畫畫)

      2. <small id='VMCRK'></small><noframes id='VMCRK'>

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

          • <legend id='VMCRK'><style id='VMCRK'><dir id='VMCRK'><q id='VMCRK'></q></dir></style></legend>
                • 本文介紹了用畫筆畫畫的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要關于在 PyQt5 上實現畫筆的幫助我已經有了一些鼠標事件代碼:

                  I need help with the implementation of the brush on PyQt5 I already have some event code for the mouse:

                  def mousePressEvent(self, event):
                      if event.button() and event.button() == Qt.LeftButton:
                          self.lastPoint = event.pos()
                          self.scribbling = True
                  
                  def mouseMoveEvent(self, event):
                      if (event.buttons() & Qt.LeftButton) and self.scribbling:
                          self.drawLineTo(event.pos())
                  
                  
                  def mouseReleaseEvent(self, event):
                      if event.button() == Qt.LeftButton and self.scribbling:
                          self.drawLineTo(event.pos())
                          self.scribbling = False
                  

                  其中聲明了畫筆繪制函數:

                  Inside of which the brush drawing function is declared:

                  def drawLineTo(self, endPoint):
                      painter = QPainter(self.image)
                      painter.setPen(QPen(self.myPenColor, self.myPenWidth, Qt.SolidLine,
                              Qt.RoundCap, Qt.RoundJoin))
                      painter.drawLine(self.lastPoint, endPoint)
                      self.modified = True
                  
                      rad = self.myPenWidth / 2 + 2
                      self.update(QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad))
                      self.lastPoint = QPoint(endPoint)
                  

                  但主要問題是這個函數是在事件本身中聲明的.因此,繪圖立即進行,我無法添加其他工具.因為與他們一起,鉛筆"將不斷被繪制.但是我需要以某種方式從那里拉出該功能并將其分配給相應的按鈕.僅通過單擊此按鈕來包含.假設我有一些工具欄:

                  But the main problem is that this function is declared in the events themselves. Therefore, drawing goes immediately, and I can not add other tools. Because together with them the "pencil" will constantly be drawn. But I need to somehow pull out the function from there and assign it to the corresponding button. To include only by clicking on this button. Let's say I have some toolbar:

                  toolbar = self.addToolBar('Инструменты')
                  toolbar.addAction(self.pen)
                  

                  有一個動作:

                  self.pen = QAction(QIcon('Image/pen.png'), 'Pencil', self)
                  self.pen.triggered.connect(self.      )
                  

                  我將如何在triggered.connect"中分配繪圖功能,并且它僅在單擊按鈕時才起作用.也許這有一些聯系,比如在 tkinter 中,在相似性中:

                  How would I do so in the "triggered.connect" assign the drawing function, and that it works only when the button is clicked. Maybe there are some bonds for this, like in tkinter, in the similarity:

                  def draw_pen(self):
                      self.parent.config(cursor="arrow")
                      self.parent.unbind("<Button-1>")
                      self.parent.unbind("<Motion>")
                      self.parent.bind("<ButtonPress-1>", self.button_press)
                      self.parent.bind('<B1-Motion>', self.draw_pencil_move)
                      self.parent.bind('<ButtonRelease-1>', self.draw_pencil_release)
                  

                  最后,我只是將此功能分配給按鈕,一切正常

                  And, in the end, I just assigned this function to the button, and everything worked fine

                  我將非常感謝您的回答,尤其是解決問題的示例或未在事件中聲明的畫筆示例

                  I will be very grateful for answers and especially for examples of solving problems or examples of brushes that are not declared in the events

                  附:如果有問題,我為我的英語道歉с:

                  P.S. I apologize for my English, if something is wrong с:

                  推薦答案

                  試試看:

                  import sys
                  from PyQt5.QtCore    import *
                  from PyQt5.QtWidgets import *
                  from PyQt5.QtGui     import *
                  
                  class MyScribbling(QMainWindow):
                  
                      def __init__(self):
                          super().__init__()
                  
                          self.penOn = QAction(QIcon('Image/ok.png'), 'Включить рисование', self)
                          self.penOn.triggered.connect(self.drawingOn)
                          self.penOff = QAction(QIcon('Image/exit.png'), 'ВЫКЛЮЧИТЬ рисование', self)
                          self.penOff.triggered.connect(self.drawingOff)
                          toolbar = self.addToolBar('Инструменты')
                          toolbar.addAction(self.penOn)
                          toolbar.addAction(self.penOff)
                  
                          self.scribbling = False
                          self.myPenColor = Qt.red      # +
                          self.myPenWidth = 3           # +
                  
                          self.lastPoint = QPoint()
                          self.image     = QPixmap("Image/picture.png")
                          self.setFixedSize(600, 600)
                          self.resize(self.image.width(), self.image.height())
                          self.show()
                  
                      # +++ 
                      def paintEvent(self, event):
                          painter = QPainter(self)
                          painter.drawPixmap(self.rect(), self.image)
                  
                      def mousePressEvent(self, event):
                          # if event.button() and event.button() == Qt.LeftButton:    # -
                          if (event.button() == Qt.LeftButton) and self.scribbling:   # +
                              self.lastPoint = event.pos()
                              # self.scribbling = True                                # -
                  
                      def mouseMoveEvent(self, event):
                          if (event.buttons() & Qt.LeftButton) and self.scribbling:
                  
                              # self.drawLineTo(event.pos())                          # -
                  
                              # +++
                              painter = QPainter(self.image)
                              painter.setPen(QPen(self.myPenColor, self.myPenWidth, 
                                                  Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
                              painter.drawLine(self.lastPoint, event.pos())
                              # self.modified = True                                  # ?
                              self.lastPoint = event.pos()
                              self.update()
                  
                              # ?
                              #rad = self.myPenWidth / 2 + 2
                              #self.update(QRect(self.lastPoint, event.pos()).normalized().adjusted(-rad, -rad, +rad, +rad))
                              #self.lastPoint = QPoint(event.pos())   
                  
                      def mouseReleaseEvent(self, event):
                          if event.button() == Qt.LeftButton and self.scribbling:
                              #self.drawLineTo(event.pos())
                              #self.scribbling = False  
                              pass
                  
                  #    Перенес в mouseMoveEvent
                  #    def drawLineTo(self, endPoint):
                  #        painter = QPainter(self.image)
                  #        painter.setPen(QPen(self.myPenColor, self.myPenWidth, Qt.SolidLine, Qt.RoundCap, Qt.RoundJoin))
                  #        painter.drawLine(self.lastPoint, endPoint)
                  #        self.modified = True  
                  #        rad = self.myPenWidth / 2 + 2
                  #        self.update(QRect(self.lastPoint, endPoint).normalized().adjusted(-rad, -rad, +rad, +rad))
                  #        self.lastPoint = QPoint(endPoint)        
                  
                      # +++    
                      def drawingOn(self):
                          self.scribbling = True
                  
                      # +++    
                      def drawingOff(self):
                          self.scribbling = False
                  
                  
                  if __name__ == '__main__':
                      app = QApplication(sys.argv)
                      mainMenu = MyScribbling()
                      sys.exit(app.exec_())        
                  

                  這篇關于用畫筆畫畫的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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='vu6dV'><tr id='vu6dV'><dt id='vu6dV'><q id='vu6dV'><span id='vu6dV'><b id='vu6dV'><form id='vu6dV'><ins id='vu6dV'></ins><ul id='vu6dV'></ul><sub id='vu6dV'></sub></form><legend id='vu6dV'></legend><bdo id='vu6dV'><pre id='vu6dV'><center id='vu6dV'></center></pre></bdo></b><th id='vu6dV'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='vu6dV'><tfoot id='vu6dV'></tfoot><dl id='vu6dV'><fieldset id='vu6dV'></fieldset></dl></div>
                      <bdo id='vu6dV'></bdo><ul id='vu6dV'></ul>
                    • <small id='vu6dV'></small><noframes id='vu6dV'>

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

                          <tfoot id='vu6dV'></tfoot>

                            <tbody id='vu6dV'></tbody>
                          1. 主站蜘蛛池模板: 国产精品精品久久久 | 日韩一区二区三区视频 | 亚洲精品99 | av片在线免费看 | 九九综合 | 亚洲精品久久久一区二区三区 | 国产在线精品免费 | 国产精品一区在线 | 国产精品国产三级国产aⅴ中文 | h片在线观看网站 | 欧美日韩中文字幕 | 欧美成年人 | 青草福利| 国产在线不卡 | 综合久久色 | 日韩视频在线免费观看 | 在线日韩| 亚洲久久一区 | 成人高清视频在线观看 | 毛片免费看 | 不卡一区 | 福利社午夜影院 | 无码日韩精品一区二区免费 | 欧美日韩一区在线 | 91一区二区 | 国产视频第一页 | 亚洲精品成人网 | 日韩视频在线一区二区 | 2019中文字幕视频 | 日本精品视频在线观看 | 欧美在线观看免费观看视频 | 91欧美精品成人综合在线观看 | 情侣av| 精品久久国产 | 一区二区三区国产精品 | 久久99国产精品 | 久久精品久久精品 | www亚洲成人 | 色999日韩 | 成人高清视频在线观看 | 手机日韩 |