I am using the following code to connect QMenu to QPushButton . When a button is pressed, a drop-down menu with several submenu items is displayed.
button=QPushButton() button.setText("Press Me") font=QtGui.QFont() button.setFont(font) button.setSizePolicy(ToolButtonSizePolicy) button.setPopupMode(QtGui.QToolButton.InstantPopup) menu=QtGui.QMenu() button.setMenu(menu) menuItem1=menu.addAction('Menu Item1') menuItem2=menu.addAction('Menu Item2')
Now, depending on the conditions, I would like to customize the display of QPushButton by providing it with text and background color. The next line of code (which should change the background color) does not affect the QPushButton connected to QMenu.
button.setStyleSheet('QPushButton {background-color: #A3C1DA}')
I would like to know how to change the background color of QPushButton as well as the color of the button text.
python qt pyqt qss qtstylesheets
alphanumeric
source share