PyQt Demo:

https://www.cnblogs.com/zach0812/p/13121523.html

 

我们知道QFormLayout 是两列的(Label 和 Feild ) ,那么如果是想要 三列,想要四列如何搞呢?

就要用到这里的网格布局了,

QGridLayout的描述:

布局管理之 QGridLayout (网格布局)

 

它是继承与QLayout 的,

 

QGridLayout的功能作用:

构造函数:

布局管理之 QGridLayout (网格布局)

 

布局管理之 QGridLayout (网格布局)
from PyQt5.Qt import * #刚开始学习可以这样一下导入
import sys

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


    def set_ui(self):
        gridLayout = QGridLayout()

        label1= QLabel("标签1")
        label1.setStyleSheet("background-color:red;")
        label2= QLabel("标签2")
        label2.setStyleSheet("background-color:green;")
        label3= QLabel("标签3")
        label3.setStyleSheet("background-color:yellow;")



        self.setLayout(gridLayout)

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

    window = Window()
    window.show()

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

相关文章: