6.6 Nesting Layouts
728x90

1. 레이아웃 중첩(Nesting Layouts)
: 복잡한 화면은 레이아웃 안에 레이아웃을 또 넣어서 만든다.
더보기


import sys
from PySide6.QtWidgets import (
QApplication, QWidget, QPushButton,
QVBoxLayout, QHBoxLayout, QLabel
)
class NestedLayout(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("중첩 레이아웃 예제")
self.resize(320, 220)
# [0] 제목용 레이블
title_label = QLabel("빈 레이블에 출력")
title_label.setStyleSheet("font-size: 14px; font-weight: bold; margin: 8px;")
# [1] 위쪽 가로 레이아웃 (QHBoxLayout)
top_layout = QHBoxLayout()
top_layout.addWidget(QPushButton("위쪽 버튼 1"))
top_layout.addWidget(QPushButton("위쪽 버튼 2"))
# [2] 아래쪽 가로 레이아웃 (QHBoxLayout)
bottom_layout = QHBoxLayout()
bottom_layout.addWidget(QPushButton("아래쪽 버튼 1"))
bottom_layout.addWidget(QPushButton("아래쪽 버튼 2"))
bottom_layout.addWidget(QPushButton("아래쪽 버튼 3"))
# [3] 세로 레이아웃(QVBoxLayout)에 두 개의 HBox를 쌓기
main_layout = QVBoxLayout(self)
main_layout.addWidget(title_label) # 맨 위 설명 레이블
main_layout.addLayout(top_layout) # 위쪽 H 레이아웃
main_layout.addLayout(bottom_layout) # 아래쪽 H 레이아웃
# 실행 영역
if __name__ == "__main__":
app = QApplication(sys.argv)
window = NestedLayout()
window.show()
sys.exit(app.exec())
2. Qt Designer 에서 Nesting Layouts 사용하기 (1)
3. Qt Designer 에서 Nesting Layouts 사용하기 (2)













