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

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

    <small id='8Kswn'></small><noframes id='8Kswn'>

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

      1. PyQt5:樣式表和來自 QWidget 的繼承

        PyQt5: stylesheet and inheritance from QWidget(PyQt5:樣式表和來自 QWidget 的繼承)

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

            <small id='4R570'></small><noframes id='4R570'>

            • <bdo id='4R570'></bdo><ul id='4R570'></ul>
                  <tbody id='4R570'></tbody>
                  <tfoot id='4R570'></tfoot>

                • 本文介紹了PyQt5:樣式表和來自 QWidget 的繼承的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

                  問題描述

                  我的代碼生成一個包含兩個 QWidget 的窗口,一個紅色 (wg1) 和一個藍色 (wg2).如果它們變成繼承自 QWidget 的 Fields(注釋掉),它們的顏色就會消失.

                  My code generates a Window containing two QWidgets, a red (wg1) and a blue (wg2) one. If they become Fields (commented out) which inherits from QWidget, their color disappears.

                  我的問題是:為什么 Field(繼承自 QWidget)需要有一行

                  My question is: Why is it necessary for a Field (which inherits from QWidget), to have the line

                  self.setAttribute(Qt.WA_StyledBackground, True)

                  在它的 __init__ 方法中,而 QWidget 不需要這一行?

                  in its __init__-method while a QWidget doesn't need this line?

                  import sys
                  from PyQt5 import QtWidgets
                  from PyQt5.QtWidgets import QWidget, QApplication, QGridLayout
                  from PyQt5.QtCore import Qt
                  
                  class Field(QWidget):
                      def __init__(self, name):
                          super().__init__()
                          self.name = name
                          # self.setAttribute(Qt.WA_StyledBackground, True)# !!!
                          
                      def mousePressEvent(self, event):
                          print(f" click makes {self.name} green")
                          self.setStyleSheet("background: #00ff00;")
                  
                  if __name__ == "__main__":
                      app = QApplication(sys.argv)
                      root = QWidget()
                      grid = QGridLayout()
                      root.setLayout(grid)
                      root.resize(300,100)
                  
                      wg1 = QWidget()
                      wg2 = QWidget()
                      # wg1 = Field('wg1')
                      # wg2 = Field('wg2')
                  
                      wg1.setStyleSheet("background: #aa1111;")
                      grid.addWidget(wg1, 0, 0)
                  
                      wg2.setStyleSheet("background: #1111aa;")
                      grid.addWidget(wg2, 0, 2)
                  
                      root.show()
                      sys.exit(app.exec_())
                  

                  推薦答案

                  解釋在樣式表參考中與 QWidget 相關的部分:

                  如果您從 QWidget 繼承,您需要為您的自定義 QWidget 提供一個paintEvent,如下所示:

                  If you subclass from QWidget, you need to provide a paintEvent for your custom QWidget as below:

                  默認情況下,QWidget 會默認執行此操作,但 QWidget 子類不會,因此您要么設置標志,要么實現paintEvent.

                  By default, QWidget does that by default, but QWidget subclasses do not, so you either set the flag or you implement the paintEvent.

                  無論如何,請考慮使用 樣式表選擇器 并避免通用/通用語法,因為它們通常會導致復雜的子小部件出現意外行為.

                  In any case, consider using stylesheet selectors and avoid generic/universal syntax as they often result in unexpected behavior for complex child widgets.

                  這篇關于PyQt5:樣式表和來自 QWidget 的繼承的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持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時顯示進度條?)

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

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

                            主站蜘蛛池模板: 超碰最新在线 | 日韩一区欧美一区 | 欧美一区二区视频 | 国产日韩一区二区三免费 | 成人国产午夜在线观看 | 国产成人精品一区二三区在线观看 | 免费黄色大片 | 欧美精品一二三 | 日批日韩在线观看 | 日本精品久久久久久久 | 色婷婷av99xx | 国产三区精品 | 国产精品一区二区免费看 | 亚洲视频 欧美视频 | 91在线一区 | 久久久一区二区三区四区 | 久热国产精品视频 | 亚洲精品中文字幕 | 久久久免费少妇高潮毛片 | 美国一级毛片a | 色五月激情五月 | 免费欧美视频 | 中文字幕免费视频 | 夜夜草av| 久久久久久久国产精品视频 | 亚洲国产成人av好男人在线观看 | 日韩国产欧美一区 | av资源在线看 | 国产乱精品一区二区三区 | 岛国毛片 | 夜夜爽99久久国产综合精品女不卡 | 国产精品久久久久久久久久久久 | 国产黄色一级电影 | 999久久久| 婷婷国产一区二区三区 | 狠狠伊人 | 亚洲在线观看视频 | 热久久国产 | 久久久精品一区二区 | 亚洲逼院| 日韩一区二区在线观看 |