QLayoutItem Class
QLayoutItem 클래스는 Q QLayout 가 조작하는 추상 항목을 제공합니다. 더 보기...
| 헤더: | #include <QLayoutItem> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| 상속된 항목: |
공개 함수
| QLayoutItem(Qt::Alignment alignment = Qt::Alignment()) | |
| virtual | ~QLayoutItem() |
| Qt::Alignment | alignment() const |
| virtual QSizePolicy::ControlTypes | controlTypes() const |
| virtual Qt::Orientations | expandingDirections() const = 0 |
| virtual QRect | geometry() const = 0 |
| virtual bool | hasHeightForWidth() const |
| virtual int | heightForWidth(int) const |
| virtual void | invalidate() |
| virtual bool | isEmpty() const = 0 |
| virtual QLayout * | layout() |
| virtual QSize | maximumSize() const = 0 |
| virtual int | minimumHeightForWidth(int w) const |
| virtual QSize | minimumSize() const = 0 |
| void | setAlignment(Qt::Alignment alignment) |
| virtual void | setGeometry(const QRect &r) = 0 |
| virtual QSize | sizeHint() const = 0 |
| virtual QSpacerItem * | spacerItem() |
| virtual QWidget * | widget() const |
상세 설명
이것은 사용자 정의 레이아웃에서 사용됩니다.
sizeHint(), minimumSize(), maximumSize() 및 expandingDirections()을 포함하여 레이아웃에 대한 정보를 반환하는 순수 가상 함수가 제공됩니다.
setGeometry() 및 geometry()을 사용하여 레이아웃의 기하학적 구조를 설정하고 가져올 수 있으며, setAlignment() 및 alignment()을 사용하여 정렬을 설정하고 가져올 수 있습니다.
isEmpty()는 레이아웃 항목이 비어 있는지 여부를 반환합니다. 구체적인 항목이 QWidget 인 경우, widget()를 사용하여 이를 가져올 수 있습니다. layout() 및 spacerItem()도 마찬가지로 적용됩니다.
일부 레이아웃은 너비와 높이가 상호 의존적입니다. 이러한 관계는 hasHeightForWidth(), heightForWidth() 및 minimumHeightForWidth()를 사용하여 표현할 수 있습니다. 자세한 설명은 Qt Quarterly 기사 “Trading Height for Width”를 참조하십시오.
QLayout도 참조하십시오 .
멤버 함수 문서
[explicit] QLayoutItem::QLayoutItem(Qt::Alignment alignment = Qt::Alignment())
alignment 를 가진 레이아웃 항목을 생성합니다. 모든 하위 클래스가 정렬을 지원하는 것은 아닙니다.
[virtual noexcept] QLayoutItem::~QLayoutItem()
QLayoutItem 를 파괴합니다.
Qt::Alignment QLayoutItem::alignment() const
이 항목의 정렬 방식을 반환합니다.
setAlignment()도 참조하십시오 .
[virtual] QSizePolicy::ControlTypes QLayoutItem::controlTypes() const
레이아웃 항목에 대한 컨트롤 유형을 하나 또는 여러 개 반환합니다. ` QWidgetItem`의 경우, 컨트롤 유형은 위젯의 크기 정책에서 비롯되며, ` QLayoutItem`의 경우, 컨트롤 유형은 레이아웃의 내용에서 파생됩니다.
QSizePolicy::controlType()도 참조하십시오 .
[pure virtual] Qt::Orientations QLayoutItem::expandingDirections() const
이 레이아웃 항목이 ` sizeHint()`보다 더 많은 공간을 사용할 수 있는지 여부를 반환합니다. ` Qt::Vertical ` 또는 ` Qt::Horizontal ` 값은 한 차원에서만 확장되기를 원함을 의미하는 반면, ` Qt::Vertical ` | ` Qt::Horizontal ` 값은 두 차원 모두에서 확장되기를 원함을 의미합니다.
[pure virtual] QRect QLayoutItem::geometry() const
이 레이아웃 항목이 차지하는 직사각형을 반환합니다.
setGeometry()도 참조하십시오 .
[virtual] bool QLayoutItem::hasHeightForWidth() const
이 레이아웃의 선호 높이가 너비에 따라 달라지는 경우 ` true `를 반환하고, 그렇지 않은 경우 ` false`를 반환합니다. 기본 구현은 `false`를 반환합니다.
너비에 따른 높이를 지원하는 레이아웃 관리자에서는 이 함수를 재구현하십시오.
heightForWidth() 및 QWidget::heightForWidth()도 참조하십시오 .
[virtual] int QLayoutItem::heightForWidth(int) const
이 레이아웃 항목의 너비를 기준으로 선호 높이는 이 함수를 통해 반환되지만, 이 기본 구현에서는 해당 너비가 사용되지 않습니다.
기본 구현은 -1을 반환하며, 이는 선호 높이가 항목의 너비와 무관함을 나타냅니다. ` hasHeightForWidth()` 함수를 사용하는 것이 이 함수를 호출한 후 -1인지 확인하는 것보다 일반적으로 훨씬 빠릅니다.
‘width for height’를 지원하는 레이아웃 관리자에서는 이 함수를 재구현해야 합니다. 일반적인 구현은 다음과 같습니다:
int MyLayout::heightForWidth(int w) const
{
if (cache_dirty || cached_width != w) {
MyLayout *that = const_cast<MyLayout *>(this);
int h = calculateHeightForWidth(w);
that->cached_hfw = h;
return h;
}
return cached_hfw;
}캐싱을 적극 권장합니다. 캐싱을 사용하지 않으면 레이아웃 처리 시간이 기하급수적으로 늘어납니다.
hasHeightForWidth()도 참조하십시오 .
[virtual] void QLayoutItem::invalidate()
이 레이아웃 항목에 저장된 모든 캐시 정보를 무효화합니다.
[pure virtual] bool QLayoutItem::isEmpty() const
이 항목이 비어 있는지, 즉 위젯이 포함되어 있는지 여부를 반환하기 위해 하위 클래스에서 구현됩니다.
[virtual] QLayout *QLayoutItem::layout()
이 항목이 ` QLayout`인 경우 ` QLayout`로 반환되고, 그렇지 않은 경우 ` nullptr `가 반환됩니다. 이 함수는 유형 안전성을 보장하는 형 변환을 제공합니다.
spacerItem() 및 widget()도 참조하십시오 .
[pure virtual] QSize QLayoutItem::maximumSize() const
이 항목의 최대 크기를 반환하기 위해 하위 클래스에서 구현됩니다.
[virtual] int QLayoutItem::minimumHeightForWidth(int w) const
주어진 너비( w)에 대해 이 위젯에 필요한 최소 높이를 반환합니다. 기본 구현은 단순히 heightForWidth(w)를 반환합니다.
[pure virtual] QSize QLayoutItem::minimumSize() const
이 항목의 최소 크기를 반환하기 위해 하위 클래스에서 구현됩니다.
void QLayoutItem::setAlignment(Qt::Alignment alignment)
이 항목의 정렬 방식을 ‘ alignment ’로 설정합니다.
참고: 항목 정렬은 시각적 효과가 나타나는 QLayoutItem 의 하위 클래스에서만 지원됩니다. 레이아웃을 위한 공백을 제공하는 QSpacerItem 를 제외하고, QLayoutItem 를 상속하는 모든 공개 Qt 클래스는 항목 정렬을 지원합니다.
alignment()도 참조하십시오 .
[pure virtual] void QLayoutItem::setGeometry(const QRect &r)
이 항목의 지오메트리를 ` r`로 설정하기 위해 하위 클래스에서 구현됩니다.
geometry()도 참조하십시오 .
[pure virtual] QSize QLayoutItem::sizeHint() const
이 항목의 선호 크기를 반환하기 위해 하위 클래스에서 구현됩니다.
[virtual] QSpacerItem *QLayoutItem::spacerItem()
이 항목이 ` QSpacerItem`인 경우 ` QSpacerItem`로 반환되고, 그렇지 않은 경우 ` nullptr `가 반환됩니다. 이 함수는 유형 안전한 형 변환을 제공합니다.
[virtual] QWidget *QLayoutItem::widget() const
이 항목이 ` QWidget`를 관리하는 경우, 해당 위젯을 반환합니다. 그렇지 않은 경우 ` nullptr `가 반환됩니다.
참고: layout() 및 spacerItem() 함수는 형 변환을수행하지만 , 이 함수는 다른 객체를 반환합니다. QLayout 및 QSpacerItem 은 QLayoutItem 을 상속받지만, QWidget 은 그렇지 않습니다.
layout() 및 spacerItem()도 참조하십시오 .
© 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.