QBoxLayout Class
QBoxLayout 클래스는 자식 위젯을 가로 또는 세로로 정렬합니다. 더 보기...
Header: | #include <QBoxLayout> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
상속합니다: | QLayout |
상속 대상 |
공용 유형
enum | Direction { LeftToRight, RightToLeft, TopToBottom, BottomToTop } |
공용 함수
QBoxLayout(QBoxLayout::Direction dir, QWidget *parent = nullptr) | |
virtual | ~QBoxLayout() |
void | addLayout(QLayout *layout, int stretch = 0) |
void | addSpacerItem(QSpacerItem *spacerItem) |
void | addSpacing(int size) |
void | addStretch(int stretch = 0) |
void | addStrut(int size) |
void | addWidget(QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()) |
QBoxLayout::Direction | direction() const |
void | insertItem(int index, QLayoutItem *item) |
void | insertLayout(int index, QLayout *layout, int stretch = 0) |
void | insertSpacerItem(int index, QSpacerItem *spacerItem) |
void | insertSpacing(int index, int size) |
void | insertStretch(int index, int stretch = 0) |
void | insertWidget(int index, QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment()) |
void | setDirection(QBoxLayout::Direction direction) |
void | setStretch(int index, int stretch) |
bool | setStretchFactor(QWidget *widget, int stretch) |
bool | setStretchFactor(QLayout *layout, int stretch) |
int | stretch(int index) const |
재구현된 공용 함수
virtual void | addItem(QLayoutItem *item) override |
virtual int | count() const override |
virtual Qt::Orientations | expandingDirections() const override |
virtual bool | hasHeightForWidth() const override |
virtual int | heightForWidth(int w) const override |
virtual void | invalidate() override |
virtual QLayoutItem * | itemAt(int index) const override |
virtual QSize | maximumSize() const override |
virtual int | minimumHeightForWidth(int w) const override |
virtual QSize | minimumSize() const override |
virtual void | setGeometry(const QRect &r) override |
virtual void | setSpacing(int spacing) override |
virtual QSize | sizeHint() const override |
virtual int | spacing() const override |
virtual QLayoutItem * | takeAt(int index) override |
상세 설명
QBoxLayout은 부모 레이아웃 또는 parentWidget()에서 가져온 공간을 가져와서 상자 행으로 나누고 관리되는 각 위젯이 하나의 상자를 채우도록 합니다.
QBoxLayout의 방향이 Qt::Horizontal 인 경우 상자는 적절한 크기로 일렬로 배치됩니다. 각 위젯(또는 다른 상자)은 최소 크기와 최대 크기를 갖습니다. 여분의 공간은 스트레치 인자에 따라 공유됩니다(자세한 내용은 아래 참조).
QBoxLayout의 방향이 Qt::Vertical 인 경우 상자는 다시 적절한 크기로 열에 배치됩니다.
가장 쉬운 방법은 편의 클래스 중 하나를 사용하는 것입니다(예: QHBoxLayout ( Qt::Horizontal 상자용) 또는 QVBoxLayout ( Qt::Vertical 상자용)). 방향을 LeftToRight, RightToLeft, TopToBottom, 또는 BottomToTop 으로 지정하여 QBoxLayout 생성자를 직접 사용할 수도 있습니다.
QBoxLayout이 최상위 레이아웃이 아닌 경우(즉, 위젯의 모든 영역과 자식을 관리하지 않는 경우), 부모 레이아웃에 추가해야만 해당 레이아웃으로 아무 작업도 할 수 있습니다. 레이아웃을 추가하는 일반적인 방법은 parentLayout->addLayout()를 호출하는 것입니다.
이 작업을 완료한 후에는 네 가지 함수 중 하나를 사용하여 QBoxLayout에 상자를 추가할 수 있습니다:
- addWidget()를 사용하여 QBoxLayout에 위젯을 추가하고 위젯의 스트레치 계수를 설정합니다. (스트레치 계수는 상자 행을 따라 적용됩니다.)
- addSpacing()를 사용하여 빈 상자를 만들면 멋지고 넓은 대화 상자를 만드는 데 사용하는 함수 중 하나입니다. 여백을 설정하는 방법은 아래를 참조하세요.
- addStretch()를 사용하여 비어 있고 늘릴 수 있는 상자를 만듭니다.
- addLayout()를 사용하여 행에 QLayout 을 포함하는 상자를 추가하고 해당 레이아웃의 늘이기 계수를 설정합니다.
insertWidget(), insertSpacing(), insertStretch() 또는 insertLayout()를 사용하여 레이아웃의 지정된 위치에 상자를 삽입합니다.
QBoxLayout에는 두 개의 여백 너비도 포함됩니다:
- setContentsMargins()는 위젯의 각 측면에 있는 바깥쪽 테두리의 너비를 설정합니다. 이것은 QBoxLayout의 각 네 면을 따라 예약된 공간의 너비입니다.
- setSpacing()는 인접한 상자 사이의 너비를 설정합니다. ( addSpacing()를 사용하여 특정 지점에 더 많은 공간을 확보할 수 있습니다.)
여백 기본값은 스타일에서 제공합니다. 대부분의 Qt 스타일이 지정하는 기본 여백은 자식 위젯의 경우 9, 윈도우의 경우 11입니다. 간격은 기본적으로 최상위 레이아웃의 여백 너비와 동일하거나 부모 레이아웃과 동일합니다.
레이아웃에서 위젯을 제거하려면 removeWidget()를 호출합니다. 위젯에서 QWidget::hide()를 호출하면 QWidget::show()가 호출될 때까지 레이아웃에서 위젯이 효과적으로 제거됩니다.
편리한 생성자 때문에 거의 항상 QBoxLayout보다는 QVBoxLayout 및 QHBoxLayout 을 사용하고 싶을 것입니다.
QGridLayout, QStackedLayout, 및 레이아웃 관리를참조하세요 .
멤버 유형 문서
enum QBoxLayout::Direction
이 유형은 상자 레이아웃의 방향을 결정하는 데 사용됩니다.
Constant | 값 | 설명 |
---|---|---|
QBoxLayout::LeftToRight | 0 | 왼쪽에서 오른쪽으로 가로. |
QBoxLayout::RightToLeft | 1 | 오른쪽에서 왼쪽으로 가로. |
QBoxLayout::TopToBottom | 2 | 위에서 아래로 세로. |
QBoxLayout::BottomToTop | 3 | 아래에서 위로 세로. |
멤버 기능 문서
[explicit]
QBoxLayout::QBoxLayout(QBoxLayout::Direction dir, QWidget *parent = nullptr)
방향 dir 과 부모 위젯 parent 을 사용하여 새 QBoxLayout을 구성합니다.
이 레이아웃은 parent 에 대한 최상위 레이아웃으로 직접 설정됩니다. 위젯에 대한 최상위 레이아웃은 하나만 있을 수 있습니다. QWidget::layout ()에 의해 반환됩니다.
direction() 및 QWidget::setLayout()도 참조하세요 .
[virtual noexcept]
QBoxLayout::~QBoxLayout()
이 상자 레이아웃을 파괴합니다.
레이아웃의 위젯은 파괴되지 않습니다.
[override virtual]
void QBoxLayout::addItem(QLayoutItem *item)
다시 구현합니다: QLayout::addItem(QLayoutItem *항목).
void QBoxLayout::addLayout(QLayout *layout, int stretch = 0)
상자 끝에 layout 를 추가하고 직렬 스트레치 계수 stretch 를 추가합니다.
insertLayout(), addItem() 및 addWidget()도 참조하세요 .
void QBoxLayout::addSpacerItem(QSpacerItem *spacerItem)
이 상자 레이아웃의 끝에 spacerItem 을 추가합니다.
addSpacing() 및 addStretch()도 참조하세요 .
void QBoxLayout::addSpacing(int size)
이 상자 레이아웃의 끝에 size 크기의 늘릴 수 없는 공간( QSpacerItem)을 추가합니다. QBoxLayout 은 기본 여백과 간격을 제공합니다. 이 함수는 추가 공간을 추가합니다.
insertSpacing(), addItem() 및 QSpacerItem 를참조하세요 .
void QBoxLayout::addStretch(int stretch = 0)
이 상자 레이아웃의 끝에 최소 크기와 스트레치 계수( stretch )가 0인 스트레치 가능한 공간( QSpacerItem)을 추가합니다.
insertStretch(), addItem() 및 QSpacerItem 를참조하세요 .
void QBoxLayout::addStrut(int size)
상자의 수직 치수(예: 상자가 LeftToRight)인 경우 높이)를 최소 size 로 제한합니다. 다른 제약 조건으로 인해 제한이 늘어날 수 있습니다.
addItem()도 참조하세요 .
void QBoxLayout::addWidget(QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment())
이 상자 레이아웃의 끝에 widget 을 추가하고, 스트레치 계수는 stretch, 정렬은 alignment 입니다.
스트레치 팩터는 QBoxLayout 의 direction 에만 적용되며, 이 QBoxLayout 의 다른 상자 및 위젯에 상대적입니다. 스트레치 계수가 높은 위젯과 상자는 더 많이 늘어납니다.
스트레치 팩터가 0이고 QBoxLayout 에 0보다 큰 스트레치 팩터를 가진 위젯이 없는 경우, 관련된 각 위젯의 QWidget:sizePolicy()에 따라 공간이 배분됩니다.
정렬은 alignment 에 의해 지정됩니다. 기본 맞춤은 0이며, 이는 위젯이 전체 셀을 채운다는 의미입니다.
insertWidget(), addItem(), addLayout(), addStretch(), addSpacing() 및 addStrut()도 참조하세요 .
[override virtual]
int QBoxLayout::count() const
재구현합니다: QLayout::count() const.
QBoxLayout::Direction QBoxLayout::direction() const
상자의 방향을 반환합니다. addWidget() 및 addSpacing()는 이 방향으로 작동하며, 스트레치는 이 방향으로 늘어납니다.
setDirection(), QBoxLayout::Direction, addWidget() 및 addSpacing()도 참조하세요 .
[override virtual]
Qt::Orientations QBoxLayout::expandingDirections() const
재구현합니다: QLayout::expandingDirections() const.
[override virtual]
bool QBoxLayout::hasHeightForWidth() const
재구현합니다: QLayoutItem::hasHeightForWidth() const.
[override virtual]
int QBoxLayout::heightForWidth(int w) const
재구현합니다: QLayoutItem::heightForWidth(int) const.
void QBoxLayout::insertItem(int index, QLayoutItem *item)
index 위치에 item 을 이 상자 레이아웃에 삽입합니다. 인덱스는 음수이거나 0에서 count() 범위 내에 있어야 합니다. index 가 음수이거나 count()인 경우 항목이 끝에 추가됩니다.
addItem(), insertWidget(), insertLayout(), insertStretch() 및 insertSpacing()도 참조하세요 .
void QBoxLayout::insertLayout(int index, QLayout *layout, int stretch = 0)
index 위치에 layout 을 삽입하고 스트레치 계수 stretch 를 사용합니다. index 이 음수이면 레이아웃이 끝에 추가됩니다.
layout 는 상자 레이아웃의 자식이 됩니다.
addLayout() 및 insertItem()도 참조하세요 .
void QBoxLayout::insertSpacerItem(int index, QSpacerItem *spacerItem)
index 위치에 최소 크기와 스트레치 계수를 0으로 하여 spacerItem 을 삽입합니다. index 이 음수인 경우 끝에 공백이 추가됩니다.
addSpacerItem(), insertStretch() 및 insertSpacing()도 참조하세요 .
void QBoxLayout::insertSpacing(int index, int size)
위치 index, 크기 size 에 늘릴 수 없는 공백( QSpacerItem)을 삽입합니다. index 이 음수이면 끝에 공백이 추가됩니다.
상자 레이아웃에는 기본 여백과 간격이 있습니다. 이 함수는 추가 공간을 추가합니다.
addSpacing(), insertItem() 및 QSpacerItem 를참조하세요 .
void QBoxLayout::insertStretch(int index, int stretch = 0)
최소 크기와 스트레치 계수가 0인 index 위치에 스트레치 가능한 공백( QSpacerItem)을 삽입합니다( stretch). index 이 음수이면 끝에 공백이 추가됩니다.
addStretch(), insertItem() 및 QSpacerItem 를참조하세요 .
void QBoxLayout::insertWidget(int index, QWidget *widget, int stretch = 0, Qt::Alignment alignment = Qt::Alignment())
index 위치에 widget 를 삽입하고, 스트레치 계수 stretch 와 정렬 alignment 을 사용합니다. index 이 음수이면 위젯이 끝에 추가됩니다.
스트레치 팩터는 QBoxLayout 의 direction 에만 적용되며, 이 QBoxLayout 의 다른 상자 및 위젯에 상대적입니다. 스트레치 계수가 높은 위젯과 상자는 더 많이 늘어납니다.
스트레치 팩터가 0이고 QBoxLayout 에 0보다 큰 스트레치 팩터를 가진 위젯이 없는 경우, 관련된 각 위젯의 QWidget:sizePolicy()에 따라 공간이 배분됩니다.
정렬은 alignment 에 의해 지정됩니다. 기본 맞춤은 0이며, 이는 위젯이 전체 셀을 채운다는 의미입니다.
addWidget() 및 insertItem()도 참조하세요 .
[override virtual]
void QBoxLayout::invalidate()
다시 구현합니다: QLayout::invalidate().
캐시된 정보를 초기화합니다.
[override virtual]
QLayoutItem *QBoxLayout::itemAt(int index) const
재구현합니다: QLayout::itemAt(int index) const.
[override virtual]
QSize QBoxLayout::maximumSize() const
재구현합니다: QLayout::maximumSize() const.
[override virtual]
int QBoxLayout::minimumHeightForWidth(int w) const
재구현합니다: QLayoutItem::minimumHeightForWidth(int w) const.
[override virtual]
QSize QBoxLayout::minimumSize() const
재구현합니다: QLayout::minimumSize() const.
void QBoxLayout::setDirection(QBoxLayout::Direction direction)
이 레이아웃의 방향을 direction 로 설정합니다.
direction()도 참조하세요 .
[override virtual]
void QBoxLayout::setGeometry(const QRect &r)
재구현합니다: QLayout::setGeometry(const QRect &r).
[override virtual]
void QBoxLayout::setSpacing(int spacing)
속성에 대한 액세스 함수를 다시 구현합니다: QLayout::spacing.
QLayout::setSpacing()를 다시 구현합니다. 간격 속성을 spacing 로 설정합니다.
QLayout::setSpacing() 및 spacing()도 참조하십시오 .
void QBoxLayout::setStretch(int index, int stretch)
위치의 스트레치 계수를 index 에서 stretch 으로 설정합니다.
stretch()도 참조하세요 .
bool QBoxLayout::setStretchFactor(QWidget *widget, int stretch)
widget 의 스트레치 계수를 stretch 으로 설정하고 이 레이아웃(하위 레이아웃 제외)에서 widget 이 발견되면 true를 반환하고 그렇지 않으면 false
을 반환합니다.
setAlignment()도 참조하세요 .
bool QBoxLayout::setStretchFactor(QLayout *layout, int stretch)
이 함수는 오버로드된 함수입니다.
레이아웃 layout 의 스트레치 계수를 stretch 로 설정하고 이 레이아웃(하위 레이아웃 제외)에 layout 이 있는 경우 true
을 반환하고 그렇지 않으면 false
을 반환합니다.
[override virtual]
QSize QBoxLayout::sizeHint() const
재구현합니다: QLayoutItem::sizeHint() const.
[override virtual]
int QBoxLayout::spacing() const
속성에 대한 액세스 함수를 다시 구현합니다: QLayout::spacing.
QLayout::spacing()를 다시 구현합니다. 간격 속성이 유효하면 해당 값이 반환됩니다. 그렇지 않으면 간격 속성의 값이 계산되어 반환됩니다. 위젯의 레이아웃 간격은 스타일에 따라 달라지므로 부모가 위젯인 경우 레이아웃의 (가로 또는 세로) 간격에 대한 스타일을 쿼리합니다. 그렇지 않으면 부모가 레이아웃인 경우 부모 레이아웃에 간격()을 쿼리합니다.
QLayout::spacing() 및 setSpacing()도 참조하세요 .
int QBoxLayout::stretch(int index) const
위치의 스트레치 계수를 반환합니다 index.
setStretch()도 참조하세요 .
[override virtual]
QLayoutItem *QBoxLayout::takeAt(int index)
재구현합니다: QLayout::takeAt(int index).
© 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.