I would like to be able to change the color of my application from a slot. For example, if user enters the wrong data into qlabel the whole QWidget turns to red color.
It is easy just to change color in code before method show(), like this:
from PyQt5 import Qt
import sys
app = QtWidgets.QApplication(sys.argv)
window = QWidget()
p = window.palette()
p.setColor(window.backgroundRole(), QtCore.Qt.red)
window.setPalette(p)
window.show()
sys.exit(app.exec_())
But I do not know how to change the color in slot, if I have this structure:
class MyWindow(QtWidgets.QWidget):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
uic.loadUi("file.ui", self)
self.sendButton.clicked.connect(self.change_color)
# what should be in change-color slot?
def change_color(self):
#.....?
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
Should I somehow call a pointer of QWidget in slot ?
What is the way to achieve proper functionality here?