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

<tfoot id='AC5Dz'></tfoot>

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

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

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

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

      1. 如何在標簽中顯示圖片和文本(PyQt)

        how to show picture and text in a label (PyQt)(如何在標簽中顯示圖片和文本(PyQt))

          <legend id='t0m0L'><style id='t0m0L'><dir id='t0m0L'><q id='t0m0L'></q></dir></style></legend>
          • <bdo id='t0m0L'></bdo><ul id='t0m0L'></ul>
            <tfoot id='t0m0L'></tfoot>

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

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

                  本文介紹了如何在標簽中顯示圖片和文本(PyQt)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我需要在標簽中顯示圖片和文字,這是我的代碼:

                  I need to show a picture and text in a label, and this is my code:

                  import sys
                  from PyQt5.QtCore import *
                  from PyQt5.QtGui import *
                  from PyQt5.QtWidgets import *
                  
                  class MyLabel(QLabel):
                      def __init__(self):
                          super(MyLabel, self).__init__()
                  
                      def paintEvent(self, QPaintEvent):
                          pos = QPoint(50, 50)
                          painter = QPainter(self)
                          painter.drawText(pos, 'hello,world')
                          painter.setPen(QColor(255, 255, 255))
                  
                  class Window(QWidget):
                      def __init__(self):
                          super(Window, self).__init__()
                          layout = QHBoxLayout(self)
                          self.label = MyLabel()
                          self.pixmap = QPixmap('icon.png')
                          self.label.setPixmap(self.pixmap)
                  
                          layout.addWidget(self.label)
                  
                  
                  if __name__ == '__main__':
                  
                      app = QApplication(sys.argv)
                      window = Window()
                      window.show()
                      sys.exit(app.exec_())
                  

                  標簽只顯示文字,缺少圖片.如何在標簽中同時顯示圖像和文本.

                  The label only display the text, and the picture is missing. How to display both image and text in the label.

                  感謝 eyllanesc 解決了這個問題.

                  Thanks for eyllanesc to solve this problem.

                  不過,我還有兩個問題.

                  However, I have another two questions.

                  發(fā)現(xiàn)如果我在MyLable的paintEvent中顯示圖片和文字,點贊:

                  I found that if I display the image and text in the paintEvent of MyLable, likes:

                  def paintEvent(self, QPaintEvent):
                      super(MyLabel, self).paintEvent(QPaintEvent)
                  
                      pos = QPoint(50, 50)
                      painter = QPainter(self)
                      painter.drawText(pos, 'hello,world')
                      painter.setPen(QColor(255, 255, 255))
                  
                      self.pixmap = QPixmap('C:\Users\zhq\Desktop\DicomTool\icon.png')
                      self.setPixmap(self.pixmap)
                  

                  即使我先顯示文本然后顯示圖像,文本也會顯示在圖像上.為什么?

                  The text was display over the image even I firstly display the text and then display the image. Why?

                  其次,當我在MyLabel的paintEvent中顯示圖片和文字沒有super(MyLabel, self).paintEvent(QPaintEvent)時,發(fā)現(xiàn)只顯示文字,而且圖片不見了:

                  Second, when I display the image and text in the paintEvent of MyLabel without the super(MyLabel, self).paintEvent(QPaintEvent), I found only the text is shown, and the picture is missing:

                  def paintEvent(self, QPaintEvent):
                      pos = QPoint(50, 50)
                      painter = QPainter(self)
                      painter.drawText(pos, 'hello,world')
                      painter.setPen(QColor(255, 255, 255))
                  
                      self.pixmap = QPixmap('C:\Users\zhq\Desktop\DicomTool\icon.png')
                      self.setPixmap(self.pixmap)
                  

                  推薦答案

                  覆蓋 paintEvent 方法你已經(jīng)移除了顯示 QPixmap 的行為,因此圖像不可見.你應該做的是首先做 QLabelpaintEvent 方法總是做的,然后只繪制文本.

                  Overwriting the paintEvent method you have removed the behavior of displaying the QPixmap so the image is not visible. What you should do is first do what the paintEvent method of QLabel always does and then just paint the text.

                  class MyLabel(QLabel):
                      def __init__(self):
                          super(MyLabel, self).__init__()
                  
                      def paintEvent(self, event):
                          super(MyLabel, self).paintEvent(event)
                          pos = QPoint(50, 50)
                          painter = QPainter(self)
                          painter.drawText(pos, 'hello,world')
                          painter.setPen(QColor(255, 255, 255))
                  

                  <小時>

                  QLabel 出于優(yōu)化的原因,僅在圖像不同時才更新圖像,因為它使用 QPixmap的cacheKey" rel="nofollow noreferrer">cacheKey(),所以只在必要時繪制.


                  QLabel for reasons of optimization only updates the image if it is different for it uses the cacheKey() of QPixmap, so only draw when necessary.

                  在第一次顯示時,文本被繪制,然后設置 QPixmap 并且由于第一次調(diào)用時沒有重繪 QPixmappaintEvent(),它再次繪制文本,然后您再次設置QPixmap,但與上一個相同,我不繪制它,而是繪制一個保存在緩存中,所以在后面調(diào)用 paintEvent() 時,它只在緩存的初始圖像上繪制文本.

                  In your first case the first time it is displayed, the text is painted, then you set the QPixmap and since no QPixmap is redrawn for the first time it calls paintEvent(), it draws the text again, then you set the QPixmap again but being the same as the previous one, I do not draw it but draw the one that is saved in the cache, so in the following times that paintEvent() is called, it only draws the text on the initial image of the cache.

                  在第二種情況下,不使用父級的paintEvent(),不使用緩存,所以QPixmap不會被繪制,在這種情況下僅繪制文本.

                  In the second case, by not using the paintEvent() of the parent, the cache is not used, so the QPixmap will not be drawn and in that case only the text is drawn.

                  注意:不建議在 paintEvent() 方法中執(zhí)行繪圖以外的任務,這可能會導致類似無限循環(huán)的問題.

                  Note: it is not advisable to do a task other than drawing in the paintEvent() method, you could cause problems like an infinite loop.

                  這篇關于如何在標簽中顯示圖片和文本(PyQt)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

                  相關文檔推薦

                  How to bind a function to an Action from Qt menubar?(如何將函數(shù)綁定到 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` 構造函數(shù)有未知關鍵字 `data`)
                  Change x-axis ticks to custom strings(將 x 軸刻度更改為自定義字符串)
                  How to show progress bar while saving file to excel in python?(如何在python中將文件保存為excel時顯示進度條?)
                  • <tfoot id='IdmMc'></tfoot>

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

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

                              <tbody id='IdmMc'></tbody>

                            <legend id='IdmMc'><style id='IdmMc'><dir id='IdmMc'><q id='IdmMc'></q></dir></style></legend>
                            主站蜘蛛池模板: 亚洲欧美国产毛片在线 | 国产日韩精品视频 | 国产一区二区福利 | 黄色av大片| 三级视频在线观看 | 久久高清免费视频 | 超碰com| 成人精品三级av在线看 | 日本毛片在线观看 | 黄色大片在线播放 | 欧美日韩一区二区三区视频 | 国产乡下妇女三片 | 五月婷婷综合在线 | 欧美一区二区三区在线观看 | 久久久一区二区三区 | 黄色成人av| 国产香蕉视频在线观看 | 在线视频一区二区三区 | 亚洲区一区二 | 黄色一级片网站 | 欧美久久网 | 天天干天天操天天射 | 色噜噜狠狠一区二区三区果冻 | 日韩欧美精品一区 | 日韩中文字幕精品 | 国产com | 韩日欧美 | 51成人网| 六月激情婷婷 | 手机看片福利永久 | 在线看的av | 欧美在线视频免费 | 午夜激情影院 | 另类ts人妖一区二区三区 | 91精品国产99久久久久久红楼 | 大乳女喂男人吃奶 | 亚洲啪啪网 | 日韩免费一区二区 | 51成人做爰www免费看网站 | 欧美激情一区二区三区 | 亚洲一区在线视频 |