QHBoxLayout用于构造水平框布局对象,QVBoxLayout用于构造垂直框布局对象。
先看完整代码:
from PySide2.QtWidgets import QApplication, QWidget, QDialog, QHBoxLayout, QVBoxLayout, QGroupBox, QPushButton
import sys
from PySide2.QtGui import QIcon, QFont
class Window(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("布局管理")
self.setGeometry(300,200,500,400)
self.setIcon()
self.createLayout()
vbox = QVBoxLayout()
vbox.addWidget(self.groupBox)
self.setLayout(vbox)
self.show()
def setIcon(self):
appIcon = QIcon("icon.png")
self.setWindowIcon(appIcon)
def createLayout(self):
self.groupBox = QGroupBox("请选择一门语言")
self.groupBox.setFont(QFont("Sanserif", 13))
hbox =QHBoxLayout()
button = QPushButton("Python", self)
button.setIcon(QIcon("Python.png"))
button.setMinimumHeight(40)
hbox.addWidget(button)


4348

被折叠的 条评论
为什么被折叠?



