QStackedWidget Class
QStackedWidget 클래스는 한 번에 하나의 위젯만 표시되는 위젯 스택을 제공합니다. 더 보기...
헤더: | #include <QStackedWidget> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
상속합니다: | QFrame |
속성
- count : const 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) |
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 : const int
이 프로퍼티는 이 스택 위젯에 포함된 위젯의 수를 보유합니다.
기본적으로 이 속성의 값은 0입니다.
함수에 액세스합니다:
int | count() const |
currentIndex() 및 widget()도 참조하세요 .
currentIndex : int
이 속성은 표시되는 위젯의 인덱스 위치를 보유합니다.
현재 위젯이 없는 경우 현재 인덱스는 -1입니다.
스택이 처음에 비어 있기 때문에 기본적으로 이 속성에는 -1 값이 포함됩니다.
함수에 액세스합니다:
int | currentIndex() const |
void | setCurrentIndex(int index) |
알림 신호:
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 에 대한 알림 신호.
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)
지정된 index 에 지정된 QStackedWidget 에 지정된 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]
void QStackedWidget::widgetRemoved(int index)
이 신호는 위젯이 제거될 때마다 발생합니다. 위젯의 index 이 파라미터로 전달됩니다.
removeWidget()도 참조하세요 .
© 2025 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.