0

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;
}
Ravi Kannan
  • 303
  • 1
  • 3
  • 11

1 Answers1

0

I found the solution. I need to put style details inside Asterisk instead of any object name. I corrected my above code with below script, I removed QPushButton in order to apply same font to all the objects.

*
{
   property : value
}
Ravi Kannan
  • 303
  • 1
  • 3
  • 11
  • I changed from QPushButton * { font-size: 30px; } to * { font-size: 30px; } to apply same font to all the objects instead of QPushButton only – Ravi Kannan Dec 17 '20 at 05:24
  • you could just have put a comma after `QPushButton` it would have worked as well – JacksonPro Dec 17 '20 at 05:35