本文共 1424 字,大约阅读时间需要 4 分钟。
我试图改变我的PNG图像的颜色后,它的颜色设置为qtwidges.QColorDialog. 用Python
--->;到
然而,当我应用我的代码时,结果是:
它改变了我的PNG图像的背景
png来源在这里:DMX\U Led
{1美元^
我写了一小部分代码示例:import os
import sys
import numpy as np
from PyQt5 import QtCore, QtGui, QtWidgets
dir_path = os.path.dirname(os.path.realpath(__file__))
class Ui_MainWindows(QtWidgets.QMainWindow):
def __init__(self):
super(Ui_MainWindows,self).__init__()
self.central_widget = QtWidgets.QWidget()
self.setCentralWidget(self.central_widget)
self.setWindowTitle("Change color PNG Test")
self.setStyleSheet("background-color:black;")
self.resize(350, 350)
self.DMX_Color = QtGui.QColor('#000000')
self.button_DMX = QtWidgets.QPushButton(self.central_widget)
print("Add ")
path_image = os.path.join(dir_path,"Ressource/Rampe3.png").replace("\\", "/")
qss = 'border-image: url({})'.format(path_image)
self.button_DMX.setGeometry(100, 100, 100, 61)
self.button_DMX.setStyleSheet(qss)
self.button_DMX.clicked.connect(self.processButton_DMX)
def processButton_DMX(self):
print("Projector DMX clicked ")
self.DMX_Color.setRed(0)
self.DMX_Color.setGreen(0)
self.DMX_Color.setBlue(255)
print("Change Color Button DMX")
effect = QtWidgets.QGraphicsColorizeEffect(self.button_DMX)
effect.setColor(self.DMX_Color)
self.button_DMX.setGraphicsEffect(effect)
def main():
app = QtWidgets.QApplication(sys.argv)
MainWindow = Ui_MainWindows()
MainWindow.show()
rc = app.exec_()
sys.exit(rc)
if __name__ == "__main__":
main()
转载地址:http://zbcpo.baihongyu.com/