📌  相关文章
📜  PyQt5 – 如何更改 MainWindow 的边框样式?

📅  最后修改于: 2022-05-13 01:54:27.490000             🧑  作者: Mango

PyQt5 – 如何更改 MainWindow 的边框样式?

当我们在 PyQt5 中创建一个窗口时,默认情况下,它没有特殊类型的边框。但是我们使用setStyleSheet()方法来改变主窗口的样式、粗细和颜色。

下面是普通边框与样式边框的样子

代码 :

# importing the required libraries
  
from PyQt5.QtCore import * 
from PyQt5.QtGui import * 
from PyQt5.QtWidgets import * 
import sys
  
  
class Window(QMainWindow):
    def __init__(self):
        super().__init__()
  
  
        # set the title
        self.setWindowTitle("Python")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # setting up the style of border
        self.setStyleSheet("border : 3px dashed blue;")
  
        # creating a label widget
        self.label_1 = QLabel("new border ", self)
  
        # moving position
        self.label_1.move(100, 100)
  
        # setting up the border
        self.label_1.setStyleSheet("border :3px solid black;")
  
        # show all the widgets
        self.show()
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :
pyqt-QMainWindow-border-style