Answer the question
In order to leave comments, you need to log in
QtDesinger + Pyqt + pushbutton how to change color on click?
There is a button whose Id = button, in QtDesinger it already has its own css.
I want the color to change to black (0, 0, 0) when pressed, but implement it in code.
def function():
form.fishing_0.setStyleSheet('background: rgb(255,0,0);')
form.fishing_0.clicked.connect(function)
Answer the question
In order to leave comments, you need to log in
Either pass the entire style with a changed color (not just the background), or pass colors as arguments when calling the window
# стилизуем через f строки, передавая цвета как аргументы
self.pushButton.setStyleSheet("QPushButton{\n"
" border-radius: 30px;\n"
f" border: 2px solid {color_1};\n"
f" background-color: {color_2};\n"
"}")
# добавляем аргументы в setupUi
def setupUi(self, MainWindow, color_1, color_2):
# если форма как отдельный модуль
import your_form
self.form = your_form.class_name()
# если в одном файле
self.form = class_name()
# вызываем форму с новыми цветами
def function(self):
self.form.setupUi(self, "rgb(255,0,0)", "rgb(255,0,0)")
self.show()
self.form.fishing_0.clicked.connect(function)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question