0
奇怪的是,雖然我成功地在PyQt應用程序中添加了一個包含透明度的背景,但大部分圖像仍爲黑色。PyQt透明背景圖像部分黑
from PyQt4.QtGui import *
import sys
class BackgroundIssue(QMainWindow):
def __init__(self):
super(BackgroundIssue, self).__init__()
def resizeEvent(self, event):
pixmap = QPixmap("res/background.png")
region = QRegion(pixmap.mask())
self.setMask(pixmap.mask())
def main():
app = QApplication(sys.argv)
window = BackgroundIssue()
palette = QPalette()
palette.setBrush(QPalette.Background,QBrush(QPixmap("res/background.png")))
window.setPalette(palette)
window.setWindowTitle("Partially Black Background Image")
window.show()
return app.exec_()
if __name__ == '__main__':
main()
結果是this而實際的圖像看起來像this。 (請注意,第一個鏈接中的白色正確運行的透明度。)
我已經看了一切,並打破了我的頭,並嘗試了一打不同的解決方案。任何人至少可以解釋這種現象稱爲什麼?
謝謝!