透明度をオンまたはオフに切り替えるPyQt4.9ウィンドウがあります。理由は、WA_TranslucentBackground属性が設定されているときに機能しないフルサイズのフォノンビデオコントロールを表示することがあるからです。 (Qtのバグのためhttps://bugreports.qt.io/browse/QTBUG-8119)WA_TranslucentBackgroundをオフにするとウィンドウの再描画を停止します
問題は、WA_TranslucentBackground属性をfalseに戻した後、それがtrueになった後にウィンドウが再描画されなくなるため、同じことが表示されたままですポイントする。興味深いことに、クリックイベントはまだ応答します。
いくつかのコード例を次に示します。インクリメントボタンをクリックすると、ボタンのテキストが更新されます。トグルボタンをクリックし、再度インクリメントボタンをクリックすると、更新が表示されなくなります。終了ボタンをクリックすると、ウィンドウが閉じて、イベントがまだ応答していることが示されます。
誰かが解決策、回避策または修正をお持ちでしたら、私はそれを感謝します。ありがとう。
import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Settings(QWidget):
def __init__(self, desktop):
QWidget.__init__(self)
self.setAttribute(Qt.WA_TranslucentBackground, True)
self.setWindowFlags(Qt.FramelessWindowHint)
self.istransparent = True
self.count = 0
self.setWindowTitle("Transparent")
self.resize(300, 150)
self.incr_button = QPushButton("Increment")
toggle_button = QPushButton("Toggle Transparency")
exit_button = QPushButton("Exit")
grid = QGridLayout()
grid.addWidget(self.incr_button, 0, 0)
grid.addWidget(toggle_button, 1, 0)
grid.addWidget(exit_button, 2, 0)
self.setLayout(grid)
self.connect(toggle_button, SIGNAL("clicked()"), self.toggle)
self.connect(self.incr_button, SIGNAL("clicked()"), self.increment)
self.connect(exit_button, SIGNAL("clicked()"), self.close)
def increment(self):
self.count = self.count + 1
self.incr_button.setText("Increment (%i)" % self.count)
def toggle(self):
self.istransparent = not self.istransparent
self.setAttribute(Qt.WA_TranslucentBackground, self.istransparent)
if __name__ == "__main__":
app = QApplication(sys.argv)
s = Settings(app.desktop())
s.show()
sys.exit(app.exec_())