Why can't the button be set size and other styles?

Why can’t the button be set size and other styles?
After using the design tool, the button control cannot be inherited because it cannot be sized.

from PyQt5.QtWidgets import *
from PyQt5.QtCore import QSize

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(345, 225)
        self.pushButton = QtWidgets.QPushButton(self)
        self.pushButton.setGeometry(QtCore.QRect(20, 30, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButt"))

class MyButton(QPushButton):
    def __init__(self):
        super(MyButton, self).__init__()
        self.setStyleSheet("background:green")  #Writing this way will not produce practical results
        self.setFixedSize(QSize(10,10)) #Writing this way will not produce practical results

class Demo(Ui_Form,QWidget):
    def __init__(self,parent=None):
        super(Demo,self).__init__(parent)
        self.setupUi(self)
        self.btn = MyButton()
        self.btn.setFixedSize(QSize(100,20))  #Writing this way will not produce practical results

if __name__ == '__main__':
    app = QApplication([])
    w = Demo()
    w.show()
    sys.exit(app.exec_())

28

Hello!

The reason this is having no effect, is that this button is invisible. You have a Ui_Form with a button in it (self.pushButton). You then create a new button called self.btn and change the dimensions of that button, but because it isn’t added to a window, or a layout, it remains invisible.

For example

from PyQt5.QtWidgets import *
from PyQt5.QtCore import QSize

import sys
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
    def setupUi(self, Form):
        Form.setObjectName("Form")
        Form.resize(345, 225)
        self.pushButton = QtWidgets.QPushButton(self)
        # self.pushButton.setGeometry(QtCore.QRect(20, 30, 75, 23))
        self.pushButton.setObjectName("pushButton")
        self.retranslateUi(Form)
        QtCore.QMetaObject.connectSlotsByName(Form)

    def retranslateUi(self, Form):
        _translate = QtCore.QCoreApplication.translate
        Form.setWindowTitle(_translate("Form", "Form"))
        self.pushButton.setText(_translate("Form", "PushButt"))


class Demo(Ui_Form,QWidget):
    def __init__(self,parent=None):
        super(Demo,self).__init__(parent)
        self.setupUi(self)
        # self.btn= MyButton() we don't create this button, instead modifying the existing one
        self.pushButton.setFixedSize(QSize(200,20))  #Writing this way will not produce practical results
         
        
if __name__ == '__main__':
    app = QApplication([])
    w = Demo()
    w.show()
    sys.exit(app.exec_())