Two methods

1. It can be set directly in the Qt Designer. See this article: Implement button rounded corner Settings in Qt Designer

2. Set the code in PyCharm:

The key is the lines of code (quotes set style) self. PushButton. SetStyleSheet (‘ ‘)

from PyQt5 import QtCore, QtWidgets from PyQt5.QtWidgets import QApplication, QMainWindow import sys class Ui_MainWindow(QMainWindow): def __init__(self,parent=None): super(Ui_MainWindow,self).__init__(parent) self.setupUi() def setupUi(self): Self.setObjectName (" mainWindow ") # Window Size self.resize(800, QPushButton(self) = QTWidget.QPushButton (self) = QPushButton(self) self.pushButton.setGeometry(QtCore.QRect(10, 240, 93, 28)) # button contents self. PushButton. SetText (" button ") # button object name (not according to the self. The pushButton. SetObjectName (" pushButton ") # set button with rounded corners self.pushButton.setStyleSheet('background-color: rgb(192, 192, 192); border-radius: 10px; border: 2px groove gray; border-style: outset; ') if __name__ == '__main__': app = QApplication(sys.argv) ui = Ui_MainWindow() ui.show() sys.exit(app.exec_())

The results

Put the above code in a py file and run it directly.

Personal aesthetic is limited, the button color is ugly, light spray. Colors can be adjusted by referring to this article: RGB color table

reference

Implement the rounded corner Settings for buttons in Qt Designer

RGB color table