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

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

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

        <tfoot id='Dz7mP'></tfoot>

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

        在 QWidget 上的 QPixmap 上繪制點(pyqt5)

        Drawing points on QPixmap on QWidget (pyqt5)(在 QWidget 上的 QPixmap 上繪制點(pyqt5))

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

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

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

                <bdo id='jmyKN'></bdo><ul id='jmyKN'></ul>
                  <tfoot id='jmyKN'></tfoot>

                1. 本文介紹了在 QWidget 上的 QPixmap 上繪制點(pyqt5)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我有一個帶有 QLayout 的 QWidget,上面有一個 QLabel.我在標簽上設置了一個 QPixmap.無論用戶單擊圖像的何處,我都想畫一個點.我定義了 mouseReleaseEvent(有效)和paintEvent(但沒有繪制點).我已經閱讀了所有類似的問題,但沒有一個解決方案對我有用.有什么幫助嗎?我的相關代碼:

                  I have a QWidget with a QLayout on which there is a QLabel. I set a QPixmap on the label. Wherever the user clicks on the image, I want to draw a point. I defined mouseReleaseEvent (which works) and paintEvent (but no points are drawn). I've read all similar questions and none of the solutions worked for me. Any help? My relevant code:

                  class ImageScroller(QtWidgets.QWidget):
                  
                      def __init__(self, img):
                          QtWidgets.QWidget.__init__(self)
                          main_layout = QtWidgets.QVBoxLayout()
                          self._image_label = QtWidgets.QLabel()
                          self._set_image(img)
                          main_layout.addWidget(self._image_label)
                          main_layout.addStretch()
                          self.setLayout(main_layout)
                  
                      def _set_image(self, img):
                          img = qimage2ndarray.array2qimage(img)
                          qimg = QtGui.QPixmap.fromImage(img)
                          self._img_pixmap = QtGui.QPixmap(qimg)
                          self._image_label.show()
                  
                      def paintEvent(self, paint_event):
                          painter = QtGui.QPainter(self)
                          painter.begin(self)
                          painter.setPen(QtGui.QPen(QtCore.Qt.red))
                          pen = QtGui.QPen()
                          pen.setWidth(20)
                          painter.setPen(pen)
                          painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
                          painter.drawPoint(300,300)
                          painter.drawLine(100, 100, 400, 400)
                          for pos in self.chosen_points:
                              painter.drawPoint(pos)
                          painter.end()
                  
                      def mouseReleaseEvent(self, cursor_event):
                          self.chosen_points.append(QtGui.QCursor().pos())
                          self.update()
                  

                  推薦答案

                  當你使用 QtGui.QCursor.pos() 是獲取光標相對于屏幕的坐標,但是當你想要繪制一個小部件,你必須在小部件的坐標中,因為它有 mapToGlobal() 方法:

                  When you use QtGui.QCursor.pos() is getting the coordinates of the cursor with respect to the screen, but when you want to paint a widget you must be in the coordinates of the widget, for it the widget has the mapToGlobal() method:

                  self.mapFromGlobal(QtGui.QCursor.pos())
                  

                  但是在這種情況下還有另一種解決方案,您必須使用返回mouseReleaseEvent的事件,該事件具有pos()方法中的信息:

                  But in this case there is another solution, you must use the event that returns mouseReleaseEvent that has the information in the pos() method:

                  cursor_event.pos()
                  

                  另一個問題是你創建的標簽在小部件上方所以你看不到點,最簡單的方法是直接用drawPixmap()QPixmap> 方法.

                  Another problem is that the label you created is above the widget so you do not see the points, the easiest thing is to draw the QPixmap directly with the drawPixmap() method.

                  完整代碼:

                  from PyQt5 import QtWidgets, QtGui, QtCore
                  
                  
                  class ImageScroller(QtWidgets.QWidget):
                      def __init__(self):
                          self.chosen_points = []
                          QtWidgets.QWidget.__init__(self)
                          self._image = QtGui.QPixmap("image.png")
                  
                      def paintEvent(self, paint_event):
                          painter = QtGui.QPainter(self)
                          painter.drawPixmap(self.rect(), self._image)
                          pen = QtGui.QPen()
                          pen.setWidth(20)
                          painter.setPen(pen)
                          painter.setRenderHint(QtGui.QPainter.Antialiasing, True)
                          painter.drawPoint(300, 300)
                          painter.drawLine(100, 100, 400, 400)
                          for pos in self.chosen_points:
                              painter.drawPoint(pos)
                  
                      def mouseReleaseEvent(self, cursor_event):
                          self.chosen_points.append(cursor_event.pos())
                          # self.chosen_points.append(self.mapFromGlobal(QtGui.QCursor.pos()))
                          self.update()
                  
                  
                  if __name__ == '__main__':
                      import sys
                  
                      app = QtWidgets.QApplication(sys.argv)
                      w = ImageScroller()
                      w.resize(640, 480)
                      w.show()
                      sys.exit(app.exec_())
                  

                  這篇關于在 QWidget 上的 QPixmap 上繪制點(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時顯示進度條?)
                    <tbody id='sk5kK'></tbody>

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

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

                        1. <i id='sk5kK'><tr id='sk5kK'><dt id='sk5kK'><q id='sk5kK'><span id='sk5kK'><b id='sk5kK'><form id='sk5kK'><ins id='sk5kK'></ins><ul id='sk5kK'></ul><sub id='sk5kK'></sub></form><legend id='sk5kK'></legend><bdo id='sk5kK'><pre id='sk5kK'><center id='sk5kK'></center></pre></bdo></b><th id='sk5kK'></th></span></q></dt></tr></i><div class="qwawimqqmiuu" id='sk5kK'><tfoot id='sk5kK'></tfoot><dl id='sk5kK'><fieldset id='sk5kK'></fieldset></dl></div>
                          • <tfoot id='sk5kK'></tfoot>
                          • <legend id='sk5kK'><style id='sk5kK'><dir id='sk5kK'><q id='sk5kK'></q></dir></style></legend>
                          • 主站蜘蛛池模板: 中文字幕在线精品 | 国产一级一级毛片 | 亚洲影视在线 | 色爱综合网| 国产激情视频在线免费观看 | 亚洲看片网站 | 亚洲精品乱码久久久久久久久 | 国产丝袜一区二区三区免费视频 | www.亚洲一区二区 | 亚洲一区二区在线播放 | 一级大片网站 | 日韩中文字幕一区二区 | 欧美视频免费在线 | 精品久久国产 | 一本色道精品久久一区二区三区 | 久久久久久久久久爱 | 韩日在线视频 | 亚洲 欧美 另类 综合 偷拍 | 九一在线 | 欧美视频二区 | 午夜精品一区二区三区在线视 | 欧美亚洲视频在线观看 | 天天碰夜夜操 | 天天干天天爱天天 | 国产中文区二幕区2012 | 欧美激情国产日韩精品一区18 | 国产一区二区三区精品久久久 | 香蕉婷婷 | 午夜精品一区二区三区在线视频 | 欧美性生活一区二区三区 | 欧美成人a | 精品视频一区二区三区在线观看 | 这里只有精品999 | 精品国产乱码久久久久久图片 | 中文成人在线 | 日日操夜夜操天天操 | 国产成人精品一区二区三区四区 | 亚洲精品久久久久久宅男 | 欧美一区二区三区精品免费 | 欧美色视频免费 | 久久精品 |