QStackedWidget Class
QStackedWidget 클래스는 한 번에 하나의 위젯만 표시되는 위젯 스택을 제공합니다. 더 보기...
| 헤더: | #include <QStackedWidget> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 상속: | QFrame |
속성
- count : int
- currentIndex : int
공개 함수
| QStackedWidget(QWidget *parent = nullptr) | |
| virtual | ~QStackedWidget() |
| int | addWidget(QWidget *widget) |
| int | count() const |
| int | currentIndex() const |
| QWidget * | currentWidget() const |
| int | indexOf(const QWidget *widget) const |
| int | insertWidget(int index, QWidget *widget) |
| void | removeWidget(QWidget *widget) |
| QWidget * | widget(int index) const |
공개 슬롯
| void | setCurrentIndex(int index) |
| void | setCurrentWidget(QWidget *widget) |
신호
| void | currentChanged(int index) |
(since 6.9) void | widgetAdded(int index) |
| void | widgetRemoved(int index) |
재구현된 보호된 함수
| virtual bool | event(QEvent *e) override |
상세 설명
QStackedWidget을 사용하면 QTabWidget 에서 제공하는 것과 유사한 사용자 인터페이스를 만들 수 있습니다. 이는 QStackedLayout 클래스를 기반으로 구축된 편의 레이아웃 위젯입니다.
QStackedLayout 와 마찬가지로, QStackedWidget도 생성되어 여러 자식 위젯("페이지")으로 채워질 수 있습니다:
QWidget *firstPageWidget = new QWidget;
QWidget *secondPageWidget = new QWidget;
QWidget *thirdPageWidget = new QWidget;
QStackedWidget *stackedWidget = new QStackedWidget;
stackedWidget->addWidget(firstPageWidget);
stackedWidget->addWidget(secondPageWidget);
stackedWidget->addWidget(thirdPageWidget);
QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(stackedWidget);
setLayout(layout);QStackedWidget은 사용자가 페이지를 전환할 수 있는 내장된 기능을 제공하지 않습니다. 이는 일반적으로 QStackedWidget 페이지의 제목을 저장하는 QComboBox 또는 QListWidget 을 통해 수행됩니다. 예를 들어:
QComboBox *pageComboBox = new QComboBox;
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
connect(pageComboBox, &QComboBox::activated,
stackedWidget, &QStackedWidget::setCurrentIndex);스택형 위젯에 위젯을 추가할 때, 위젯들은 내부 목록에 추가됩니다. indexOf() 함수는 해당 목록에서 위젯의 인덱스를 반환합니다. 위젯은 addWidget() 함수를 사용하여 목록의 끝에 추가하거나, insertWidget() 함수를 사용하여 지정된 인덱스 위치에 삽입할 수 있습니다. removeWidget() 함수는 스택형 위젯에서 위젯을 제거합니다. 스택형 위젯에 포함된 위젯의 개수는 count() 함수를 사용하여 확인할 수 있습니다.
widget() 함수는 지정된 인덱스 위치에 있는 위젯을 반환합니다. 화면에 표시되는 위젯의 인덱스는 currentIndex() 함수를 통해 확인되며, setCurrentIndex() 함수를 사용하여 변경할 수 있습니다. 마찬가지로, 현재 표시된 위젯은 currentWidget() 함수를 사용하여 조회할 수 있으며, setCurrentWidget() 함수를 사용하여 변경할 수 있습니다.
스택형 위젯 내의 현재 위젯이 변경되거나 위젯이 스택형 위젯에서 제거될 때마다, 각각 currentChanged() 및 widgetRemoved() 신호가 발생합니다.
QStackedLayout 및 QTabWidget항목도 참조하십시오 .
속성 설명서
[read-only] count : int
이 속성은 이 스택형 위젯에 포함된 위젯의 개수를 나타냅니다.
기본적으로 이 속성의 값은 0입니다.
액세스 함수:
| int | count() const |
currentIndex() 및 widget()도 참조하십시오 .
currentIndex : int
이 속성은 현재 표시 중인 위젯의 인덱스 위치를 저장합니다.
현재 위젯이 없는 경우 현재 인덱스는 -1입니다.
기본적으로 스택은 처음에 비어 있으므로 이 속성의 값은 -1입니다.
액세스 함수:
| int | currentIndex() const |
| void | setCurrentIndex(int index) |
Notifier 신호:
| void | currentChanged(int index) |
currentWidget() 및 indexOf()도 참조하십시오 .
멤버 함수 문서
[explicit] QStackedWidget::QStackedWidget(QWidget *parent = nullptr)
지정된 ` parent`를 사용하여 `QStackedWidget`을 생성합니다.
addWidget() 및 insertWidget()도 참조하십시오 .
[virtual noexcept] QStackedWidget::~QStackedWidget()
이 중첩된 위젯을 제거하고, 할당된 모든 리소스를 해제합니다.
int QStackedWidget::addWidget(QWidget *widget)
지정된 ` widget `을 ` QStackedWidget `에 추가하고 인덱스 위치를 반환합니다. ` widget `의 소유권은 ` QStackedWidget`로 이전됩니다.
이 함수가 호출되기 전에 ` QStackedWidget `가 비어 있는 경우, ` widget `가 현재 위젯이 됩니다.
insertWidget(), removeWidget(), setCurrentWidget()도 참조하십시오 .
[signal] void QStackedWidget::currentChanged(int index)
이 신호는 현재 위젯이 변경될 때마다 발생합니다.
이 매개변수에는 새로운 현재 위젯의 ` index `가 포함되며, 새로운 위젯이 없는 경우(예: ` QStackedWidget`에 위젯이 없는 경우)에는 -1이 포함됩니다.
참고: 속성 currentIndex 에 대한Notifier 신호입니다.
currentWidget() 및 setCurrentWidget()도 참조하십시오 .
QWidget *QStackedWidget::currentWidget() const
현재 위젯을 반환하거나, 자식 위젯이 없는 경우 ` nullptr `를 반환합니다.
currentIndex() 및 setCurrentWidget()도 참조하십시오 .
[override virtual protected] bool QStackedWidget::event(QEvent *e)
QFrame::event(QEvent *e)를 재구현합니다.
int QStackedWidget::indexOf(const QWidget *widget) const
주어진 widget 의 인덱스를 반환하며, 주어진 widget 가 QStackedWidget 의 자식이 아닌 경우 -1을 반환합니다.
currentIndex() 및 widget()도 참조하십시오 .
int QStackedWidget::insertWidget(int index, QWidget *widget)
QStackedWidget 의 지정된 index 위치에 지정된 widget 을 삽입합니다. widget 의 소유권은 QStackedWidget 로 이전됩니다. index 가 범위를 벗어난 경우, widget 가 추가됩니다(이 경우 반환되는 값은 widget 의 실제 인덱스입니다).
이 함수가 호출되기 전에 ` QStackedWidget `가 비어 있었다면, 지정된 ` widget `가 현재 위젯이 됩니다.
현재 인덱스 이하인 위치에 새 위젯을 삽입하면 현재 인덱스가 증가하지만, 현재 위젯은 유지됩니다.
addWidget(), removeWidget(), setCurrentWidget()도 참조하십시오 .
void QStackedWidget::removeWidget(QWidget *widget)
QStackedWidget 에서 widget 를 제거합니다. 즉, widget 는 삭제되지 않고 단순히 스택 레이아웃에서 제거되어 숨겨지게 됩니다.
참고: ` widget `의부모 객체와 부모 위젯은 여전히 ` QStackedWidget`로 유지됩니다. 애플리케이션에서 제거된 ` widget`를 재사용하려는 경우, 이를 다시 부모 객체에 연결하는 것이 권장됩니다.
addWidget(), insertWidget(), currentWidget()도 참조하십시오 .
[slot] void QStackedWidget::setCurrentWidget(QWidget *widget)
현재 위젯을 지정된 ‘ widget ’로 설정합니다. 새로운 현재 위젯은 이미 이 중첩된 위젯 내에 포함되어 있어야 합니다.
currentWidget() 및 setCurrentIndex()도 참조하십시오 .
QWidget *QStackedWidget::widget(int index) const
지정된 index 에 있는 위젯을 반환하며, 해당 위젯이 없는 경우 nullptr 를 반환합니다.
currentWidget() 및 indexOf()도 참조하십시오 .
[signal, since 6.9] void QStackedWidget::widgetAdded(int index)
이 신호는 위젯이 추가되거나 삽입될 때마다 발생합니다. 위젯의 ` index `가 매개변수로 전달됩니다.
이 함수는 Qt 6.9에서 도입되었습니다.
addWidget() 및 insertWidget()도 참조하십시오 .
[signal] void QStackedWidget::widgetRemoved(int index)
이 신호는 위젯이 제거될 때마다 발생합니다. 위젯의 ` index `가 매개변수로 전달됩니다.
removeWidget()도 참조하십시오 .
© 2026 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.