python PyQt5 QVBoxLayout 垂直布局管理
生活随笔
收集整理的這篇文章主要介紹了
python PyQt5 QVBoxLayout 垂直布局管理
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
https://doc.qt.io/qtforpython/PySide2/QtWidgets/QVBoxLayout.html?highlight=qvboxlayout#PySide2.QtWidgets.QVBoxLayout
文章目錄
- 繼承關系
- 細節描述
繼承關系
細節描述
此類用于構造垂直框布局對象。 有關詳細信息,請參見QBoxLayout。
該類的最簡單用法是這樣的:(不過直接運行不了,,不知咋弄的??)
window = QWidget() button1 = QPushButton("One") button2 = QPushButton("Two") button3 = QPushButton("Three") button4 = QPushButton("Four") button5 = QPushButton("Five")layout = QVBoxLayout()layout.addWidget(button1) layout.addWidget(button2) layout.addWidget(button3) layout.addWidget(button4) layout.addWidget(button5)window.setLayout(layout) window.show()后來修改了以下,能顯示了,但不知道是否符合規范?
# -*- coding: utf-8 -*- # Dontla 20200420import sys from PyQt5.QtWidgets import QWidget, QApplication, QPushButton, QVBoxLayoutclass Example(QWidget):def __init__(self):super().__init__()self.initUI()def initUI(self):self.setGeometry(300, 300, 250, 150)self.setWindowTitle('QVBoxLayout')button1 = QPushButton("One")button2 = QPushButton("Two")button3 = QPushButton("Three")button4 = QPushButton("Four")button5 = QPushButton("Five")layout = QVBoxLayout()layout.addWidget(button1)layout.addWidget(button2)layout.addWidget(button3)layout.addWidget(button4)layout.addWidget(button5)self.setLayout(layout)self.show()if __name__ == '__main__':app = QApplication(sys.argv)ex = Example()sys.exit(app.exec_())首先,我們在布局中創建所需的小部件。 然后,我們創建QVBoxLayout對象,并將小部件添加到布局中。 最后,我們調用setLayout()將QVBoxLayout對象安裝到小部件上。 那時,布局中的小部件將重新進行父級化,以將窗口作為其父級。
See alsoQHBoxLayoutQGridLayoutQStackedLayoutLayout ManagementBasic Layouts Example class QVBoxLayout? QVBoxLayout(parent)param parent QWidget構造一個新的垂直框。 您必須將其添加到另一個布局。
使用父parent構造一個新的頂級垂直框。
總結
以上是生活随笔為你收集整理的python PyQt5 QVBoxLayout 垂直布局管理的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python PyQt5 QSlider
- 下一篇: python PyQt5 QtWidge