11. PyQt6 QHBoxLayout
2023-10-17 python 648
import sys
from PyQt6.QtWidgets import QApplication, QMainWindow, QHBoxLayout, QVBoxLayout, QPushButton, QWidget
from PyQt6.QtGui import QGuiApplication
class App(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.setWindowTitle("PyQt6 QHBoxLayout")
ok_button = QPushButton("确定")
cancel_button = QPushButton("取消")
hbox = QHBoxLayout()
hbox.addStretch(1)
hbox.addWidget(ok_button)
hbox.addWidget(cancel_button)
vbox = QVBoxLayout()
vbox.addStretch(1)
vbox.addLayout(hbox)
w = QWidget()
w.setLayout(vbox)
self.setCentralWidget(w)
self.setGeometry(100, 100, 400, 300)
self.center()
def center(self):
qr = self.frameGeometry()
cp = QGuiApplication.primaryScreen().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
if __name__ == "__main__":
app = QApplication(sys.argv)
cls_app = App()
cls_app.show()
sys.exit(app.exec())
很赞哦! (0)
文章评论
-
-
-
0条评论