样式控制-QSS  样式表

概念:

样式控制-QSS  样式表

from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

class Window(QWidget):
    def __init__(self):
        super().__init__()
        self.setWindowTitle("QSS的学习")
        self.resize(400,400)
        self.set_ui()


    def set_ui(self):
        box1 = QWidget(self)
        box2 = QWidget(self)

        box1.setStyleSheet("background-color:orange;")
        box2.setStyleSheet("background-color:cyan;")

        #box1
        label1 = QLabel("标签1",box1)
        label1.move(50,50)
        btn1 = QPushButton("按钮1",box1)
        btn1.move(100,100)

        #box2
        label2 = QLabel("标签1",box2)
        label2.move(50,50)
        btn2 = QPushButton("按钮1",box2)
        btn2.move(100,100)
        
        ###########################################################
        # 此时box1 和box2 中的控件 也默认跟随它们设置的颜色
        ###########################################################

        v_layout = QVBoxLayout()
        self.setLayout(v_layout)

        v_layout.addWidget(box1)
        v_layout.addWidget(box2)



if __name__ == '__main__':
    app =QApplication(sys.argv)

    window = Window()
    window.show()

    sys.exit(app.exec_())
View Code

相关文章:

  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
  • 2021-06-01
  • 2021-05-15
  • 2021-11-10
  • 2022-01-22
猜你喜欢
  • 2021-07-11
  • 2021-07-10
  • 2022-12-23
  • 2022-12-23
  • 2021-04-06
  • 2021-07-30
  • 2022-12-23
相关资源
相似解决方案