I am using below PySide2 code and external stylesheet. I want to use same font size for all the objects. I tried to use * selector, (Select all elements) in external stylesheet.
Same font size is not applying for all the objects. I did not understand the mistake I did.
I followed the below link to fix the problem with # selector by using .setObjectName("okButton").
But * selector is not working.
https://doc.qt.io/qt-5/stylesheet-reference.html
Qt Stylesheets : Unable to use ID Selector
My PySide2 code as below
import sys
from PySide2.QtWidgets import QWidget,QApplication,QPushButton
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.okButton = QPushButton("Ok",self)
self.okButton.setGeometry(30,50,100,25)
self.cancelButton = QPushButton("Cancel",self)
self.cancelButton.setGeometry(30,100,100,25)
self.abortButton = QPushButton("Abort",self)
self.abortButton.setGeometry(30,150,100,25)
self.okButton.setObjectName("okButton")
self.abortButton.setObjectName("abortButton")
self.abortButton.setStyleSheet("font-size: 14px;")
app = QApplication(sys.argv)
mystyle="style.qss"
with open(mystyle,"r") as ss:
app.setStyleSheet(ss.read())
window = MainWindow()
window.show()
sys.exit(app.exec_())
My QSS script
QPushButton
{
color:white;
background-color:blue;
}
QPushButton#okButton
{
color:white;
background-color:red;
}
QPushButton#abortButton
{
color:white;
background-color:orange;
}
QPushButton *
{
font-size: 30px;
}