레이아웃
FlexLayout 플렉스 레이아웃
CSS Flexbox에서 영감을 받은 QLayout 관리자로 주축/교차축 정렬, 줄바꿈 및 항목별 유연한 비율 배분을 지원합니다.
예제
속성 미리 보기를 불러오지 못했습니다. 속성 미리 보기를 다시 선택해 재시도하세요.

사용법
반응형 줄바꿈 및 유연 확장
부모 위젯에 설치하고 wrap, justifyContent, 간격 및 ItemOptions를 구성하세요.
#include <FluentQt/Layout.h>
using namespace fluent::layout;
#pragma once
#include <FluentQt/FluentQt.h>
#include <QBoxLayout>
#include <algorithm>
namespace fluent::gallery {
class FlexLayoutSample final : public QWidget {
public:
explicit FlexLayoutSample(QWidget* parent = nullptr) : QWidget(parent)
{
auto* vbox = new QVBoxLayout(this);
vbox->setContentsMargins(0, 0, 0, 0);
vbox->setSpacing(10);
auto* controls = new QWidget(this);
auto* ctrlRow = new QHBoxLayout(controls);
ctrlRow->setContentsMargins(0, 0, 0, 0);
ctrlRow->setSpacing(10);
auto* justify = new basicinput::ComboBox(controls);
justify->setAccessibleName(QStringLiteral("Justify content"));
justify->addItems({QStringLiteral("FlexStart"), QStringLiteral("Center"), QStringLiteral("FlexEnd"),
QStringLiteral("SpaceBetween"), QStringLiteral("SpaceAround")});
auto* wrapCheck = new basicinput::CheckBox(QStringLiteral("Wrap lines"), controls);
wrapCheck->setChecked(true);
auto* growCheck = new basicinput::CheckBox(QStringLiteral("Grow primary (flexGrow)"), controls);
growCheck->setChecked(false);
ctrlRow->addWidget(justify);
ctrlRow->addWidget(wrapCheck);
ctrlRow->addWidget(growCheck);
ctrlRow->addStretch();
vbox->addWidget(controls);
auto* widthBar = new QWidget(this);
auto* widthRow = new QHBoxLayout(widthBar);
widthRow->setContentsMargins(0, 0, 0, 0);
widthRow->setSpacing(10);
auto* widthLabel = new textfields::Label(QStringLiteral("Container width: 340 px"), widthBar);
auto* widthSlider = new basicinput::Slider(Qt::Horizontal, widthBar);
widthSlider->setAccessibleName(QStringLiteral("Container width"));
widthSlider->setRange(220, 560);
widthSlider->setValue(340);
widthSlider->setFixedWidth(220);
widthRow->addWidget(widthLabel);
widthRow->addWidget(widthSlider);
widthRow->addStretch();
vbox->addWidget(widthBar);
auto* surface = new layout::Card(this);
auto* flex = new layout::FlexLayout(surface);
flex->setContentsMargins(12, 12, 12, 12);
flex->setGap(8);
flex->setWrap(layout::FlexLayout::Wrap::Wrap);
auto* primary = new basicinput::Button(QStringLiteral("Primary"), surface);
primary->setFluentStyle(basicinput::Button::Accent);
flex->addWidget(primary);
flex->addWidget(new basicinput::Button(QStringLiteral("Filters"), surface));
flex->addWidget(new basicinput::Button(QStringLiteral("Metrics"), surface));
flex->addWidget(new basicinput::Button(QStringLiteral("Alerts"), surface));
flex->addWidget(new basicinput::Button(QStringLiteral("Export"), surface));
flex->addWidget(new basicinput::Button(QStringLiteral("Settings"), surface));
vbox->addWidget(surface);
const auto applyWidth = [surface, flex](int w) {
surface->setFixedWidth(w);
surface->setFixedHeight(std::max(56, flex->heightForWidth(w)));
};
applyWidth(340);
QObject::connect(justify, qOverload<int>(&basicinput::ComboBox::currentIndexChanged), flex, [flex](int idx) {
const layout::FlexLayout::JustifyContent modes[] = {layout::FlexLayout::JustifyContent::FlexStart,
layout::FlexLayout::JustifyContent::Center, layout::FlexLayout::JustifyContent::FlexEnd,
layout::FlexLayout::JustifyContent::SpaceBetween, layout::FlexLayout::JustifyContent::SpaceAround};
if (idx >= 0 && idx < 5)
flex->setJustifyContent(modes[idx]);
});
QObject::connect(wrapCheck, &basicinput::CheckBox::toggled, flex, [flex, widthSlider, applyWidth](bool on) {
flex->setWrap(on ? layout::FlexLayout::Wrap::Wrap : layout::FlexLayout::Wrap::NoWrap);
applyWidth(widthSlider->value());
});
QObject::connect(growCheck, &basicinput::CheckBox::toggled, flex,
[flex, primary, widthSlider, applyWidth](bool on) {
layout::FlexItemOptions opts;
opts.flexGrow = on ? 1.0 : 0.0;
flex->setItemOptions(primary, opts);
applyWidth(widthSlider->value());
});
QObject::connect(widthSlider, &basicinput::Slider::valueChanged, widthLabel, [widthLabel, applyWidth](int w) {
widthLabel->setText(QStringLiteral("Container width: %1 px").arg(w));
applyWidth(w);
});
}
};
} // namespace fluent::galleryimport fluentqt
from PySide6.QtCore import Qt
from PySide6.QtWidgets import QHBoxLayout, QVBoxLayout, QWidget
root = QWidget()
vbox = QVBoxLayout(root)
vbox.setContentsMargins(0, 0, 0, 0)
vbox.setSpacing(10)
controls = QWidget(root)
ctrl_row = QHBoxLayout(controls)
ctrl_row.setContentsMargins(0, 0, 0, 0)
ctrl_row.setSpacing(10)
justify = fluentqt.ComboBox(controls)
justify.setAccessibleName("Justify content")
justify.addItems(
["FlexStart", "Center", "FlexEnd", "SpaceBetween", "SpaceAround"]
)
wrap_check = fluentqt.CheckBox("Wrap lines", controls)
wrap_check.setChecked(True)
grow_check = fluentqt.CheckBox("Grow primary (flexGrow)", controls)
grow_check.setChecked(False)
ctrl_row.addWidget(justify)
ctrl_row.addWidget(wrap_check)
ctrl_row.addWidget(grow_check)
ctrl_row.addStretch()
vbox.addWidget(controls)
width_bar = QWidget(root)
width_row = QHBoxLayout(width_bar)
width_row.setContentsMargins(0, 0, 0, 0)
width_row.setSpacing(10)
width_label = fluentqt.Label("Container width: 340 px", width_bar)
width_slider = fluentqt.Slider(Qt.Horizontal, width_bar)
width_slider.setAccessibleName("Container width")
width_slider.setRange(220, 560)
width_slider.setValue(340)
width_slider.setFixedWidth(220)
width_row.addWidget(width_label)
width_row.addWidget(width_slider)
width_row.addStretch()
vbox.addWidget(width_bar)
surface = fluentqt.Card(root)
flex = fluentqt.FlexLayout(surface)
flex.setContentsMargins(12, 12, 12, 12)
flex.setGap(8)
flex.setWrap(fluentqt.FlexLayout.Wrap.Wrap)
primary = fluentqt.Button("Primary", surface)
primary.setFluentStyle(fluentqt.Button.Accent)
flex.addWidget(primary)
flex.addWidget(fluentqt.Button("Filters", surface))
flex.addWidget(fluentqt.Button("Metrics", surface))
flex.addWidget(fluentqt.Button("Alerts", surface))
flex.addWidget(fluentqt.Button("Export", surface))
flex.addWidget(fluentqt.Button("Settings", surface))
vbox.addWidget(surface)
J = fluentqt.FlexLayout.JustifyContent
W = fluentqt.FlexLayout.Wrap
modes = [J.FlexStart, J.Center, J.FlexEnd, J.SpaceBetween, J.SpaceAround]
def apply_width(width):
surface.setFixedWidth(width)
surface.setFixedHeight(max(56, flex.heightForWidth(width)))
def on_justify(idx):
flex.setJustifyContent(modes[idx])
def on_wrap(checked):
flex.setWrap(W.Wrap if checked else W.NoWrap)
apply_width(width_slider.value())
def on_grow(checked):
opts = fluentqt.FlexItemOptions()
opts.flexGrow = 1.0 if checked else 0.0
flex.setItemOptions(primary, opts)
apply_width(width_slider.value())
def on_width(width):
width_label.setText(f"Container width: {width} px")
apply_width(width)
apply_width(340)
justify.currentIndexChanged.connect(on_justify)
wrap_check.toggled.connect(on_wrap)
grow_check.toggled.connect(on_grow)
width_slider.valueChanged.connect(on_width)API
선언 보기일치하는 API 멤버가 없습니다.
fluent::layout::FlexLayout
상속 대상 QLayout
CSS Flexbox에서 영감을 받아 선택적 줄바꿈과 함께 주축 및 교차축으로 자식 위젯을 배치하는 레이아웃 관리자.
생성자
소멸자
열거형
enum class Direction주축의 배치 방향입니다. 행은 부모 위젯의 읽기 방향을 따릅니다.
Row = 0RowReverse = 1Column = 2ColumnReverse = 3
enum class Wrap줄 간 줄바꿈 동작.
NoWrap = 0Wrap = 1WrapReverse = 2
enum class JustifyContent주축 정렬 및 간격 배치 모드.
FlexStart = 0FlexEnd = 1Center = 2SpaceBetween = 3SpaceAround = 4SpaceEvenly = 5
enum class AlignItems한 플렉스 줄 내부에서의 교차축 항목 정렬.
Stretch = 0FlexStart = 1FlexEnd = 2Center = 3
enum class AlignContent여러 줄의 교차축 분배 모드.
Stretch = 0FlexStart = 1FlexEnd = 2Center = 3SpaceBetween = 4SpaceAround = 5
메서드
Direction direction() const항목이 배치되는 주축 및 정렬 방향.
void setDirection(Direction direction)항목이 배치되는 주축 및 정렬 방향.
Wrap wrap() const항목이 주축의 가용 공간을 초과할 때의 줄바꿈 모드.
void setWrap(Wrap wrap)항목이 주축의 가용 공간을 초과할 때의 줄바꿈 모드.
JustifyContent justifyContent() const주축을 따른 항목과 여유 공간의 배치 방식.
void setJustifyContent(JustifyContent justify)주축을 따른 항목과 여유 공간의 배치 방식.
AlignItems alignItems() const각 플렉스 줄 내에서 교차축을 따른 항목 정렬 방식.
void setAlignItems(AlignItems align)각 플렉스 줄 내에서 교차축을 따른 항목 정렬 방식.
AlignContent alignContent() const교차축에 여유 공간이 있을 때 줄바꿈된 행의 교차축 분배 방식.
void setAlignContent(AlignContent align)교차축에 여유 공간이 있을 때 줄바꿈된 행의 교차축 분배 방식.
int rowGap() const연속된 행 사이의 세로 간격(논리 픽셀).
void setRowGap(int gap)연속된 행 사이의 세로 간격(논리 픽셀).
int columnGap() const연속된 열 사이의 가로 간격(논리 픽셀).
void setColumnGap(int gap)연속된 열 사이의 가로 간격(논리 픽셀).
void setGap(int gap)rowGap과 columnGap을 동일한 값으로 일괄 설정합니다.
void addWidget(QWidget* widget, const FlexItemOptions& options)항목별 플렉스 옵션과 함께 위젯을 추가합니다.
void setItemOptions(QWidget* widget, const FlexItemOptions& options)관리 중인 자식 위젯의 플렉스 옵션을 업데이트합니다.
FlexItemOptions itemOptions(const QWidget* widget) const@p widget에 연결된 플렉스 옵션을 반환하며, 추적되지 않는 경우 기본값을 반환합니다.
속성
Direction direction항목이 배치되는 주축 및 정렬 방향.
읽기direction()쓰기setDirection()알림 신호directionChanged()Wrap wrap항목이 주축의 가용 공간을 초과할 때의 줄바꿈 모드.
읽기wrap()쓰기setWrap()알림 신호wrapChanged()JustifyContent justifyContent주축을 따른 항목과 여유 공간의 배치 방식.
읽기justifyContent()쓰기setJustifyContent()알림 신호justifyContentChanged()AlignItems alignItems각 플렉스 줄 내에서 교차축을 따른 항목 정렬 방식.
읽기alignItems()쓰기setAlignItems()알림 신호alignItemsChanged()AlignContent alignContent교차축에 여유 공간이 있을 때 줄바꿈된 행의 교차축 분배 방식.
읽기alignContent()쓰기setAlignContent()알림 신호alignContentChanged()int rowGap연속된 행 사이의 세로 간격(논리 픽셀).
읽기rowGap()쓰기setRowGap()알림 신호rowGapChanged()int columnGap연속된 열 사이의 가로 간격(논리 픽셀).
읽기columnGap()쓰기setColumnGap()알림 신호columnGapChanged()
시그널
void directionChanged(Direction direction)항목이 배치되는 주축 및 정렬 방향.
void wrapChanged(Wrap wrap)항목이 주축의 가용 공간을 초과할 때의 줄바꿈 모드.
void justifyContentChanged(JustifyContent justifyContent)주축을 따른 항목과 여유 공간의 배치 방식.
void alignItemsChanged(AlignItems alignItems)각 플렉스 줄 내에서 교차축을 따른 항목 정렬 방식.
void alignContentChanged(AlignContent alignContent)교차축에 여유 공간이 있을 때 줄바꿈된 행의 교차축 분배 방식.
void rowGapChanged(int rowGap)연속된 행 사이의 세로 간격(논리 픽셀).
void columnGapChanged(int columnGap)연속된 열 사이의 가로 간격(논리 픽셀).
타입 및 별칭
using ItemOptions = FlexItemOptionsC++ 호출자를 위한 FlexItemOptions의 하위 호환 별칭.
Qt 기본 클래스 문서: QLayout
fluent::layout::FlexItemOptions
FlexLayout의 항목별 플렉스 크기, 정렬 순서 및 교차축 재정의 옵션.