I am using following code to connect QMenu to QPushButton. When button is clicked a pull-down menu with multiple sub-menu\'s items is shown.
I would add a comment to Trilarions answer, but not enough rep..
I was able to use his suggestion, without removing borders by
self.show()
self.button.setStyleSheet('background-color: red;')
AFTER doing a .show() on my application. not sure why after works but not before. If anyone can explain that would be great
For those who still want to change color of button with the instruction
button.setStyleSheet('QPushButton {background-color: #A3C1DA}')
and not able to do so, just modify the above instruction to
button.setStyleSheet('QPushButton {background-color: #A3C1DA; border: none}')
And it will change the button color, so the trick is to remove the border
Apart from some inconsistencies with your code example setting the background color and text color of a QPushButton works just fine with:
setStyleSheet('QPushButton {background-color: #A3C1DA; color: red;}')
Example (using PySide):
from PySide import QtGui
app = QtGui.QApplication([])
button = QtGui.QPushButton()
button.setStyleSheet('QPushButton {background-color: #A3C1DA; color: red;}')
button.setText('Press Me')
menu = QtGui.QMenu()
menuItem1 = menu.addAction('Menu Item1')
menuItem2 = menu.addAction('Menu Item2')
button.setMenu(menu)
button.show()
app.exec_()
results in:
