이 페이지에서

QGraphicsGridLayout Class

QGraphicsGridLayout 클래스는 Graphics View에서 위젯을 관리하기 위한 그리드 레이아웃을 제공합니다. 더 보기...

헤더: #include <QGraphicsGridLayout>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
상속: QGraphicsLayout

공개 함수

QGraphicsGridLayout(QGraphicsLayoutItem *parent = nullptr)
virtual ~QGraphicsGridLayout()
void addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = Qt::Alignment())
void addItem(QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())
Qt::Alignment alignment(QGraphicsLayoutItem *item) const
Qt::Alignment columnAlignment(int column) const
int columnCount() const
qreal columnMaximumWidth(int column) const
qreal columnMinimumWidth(int column) const
qreal columnPreferredWidth(int column) const
qreal columnSpacing(int column) const
int columnStretchFactor(int column) const
qreal horizontalSpacing() const
QGraphicsLayoutItem *itemAt(int row, int column) const
void removeItem(QGraphicsLayoutItem *item)
Qt::Alignment rowAlignment(int row) const
int rowCount() const
qreal rowMaximumHeight(int row) const
qreal rowMinimumHeight(int row) const
qreal rowPreferredHeight(int row) const
qreal rowSpacing(int row) const
int rowStretchFactor(int row) const
void setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
void setColumnAlignment(int column, Qt::Alignment alignment)
void setColumnFixedWidth(int column, qreal width)
void setColumnMaximumWidth(int column, qreal width)
void setColumnMinimumWidth(int column, qreal width)
void setColumnPreferredWidth(int column, qreal width)
void setColumnSpacing(int column, qreal spacing)
void setColumnStretchFactor(int column, int stretch)
void setHorizontalSpacing(qreal spacing)
void setRowAlignment(int row, Qt::Alignment alignment)
void setRowFixedHeight(int row, qreal height)
void setRowMaximumHeight(int row, qreal height)
void setRowMinimumHeight(int row, qreal height)
void setRowPreferredHeight(int row, qreal height)
void setRowSpacing(int row, qreal spacing)
void setRowStretchFactor(int row, int stretch)
void setSpacing(qreal spacing)
void setVerticalSpacing(qreal spacing)
qreal verticalSpacing() const

재구현된 공용 함수

virtual int count() const override
virtual void invalidate() override
virtual QGraphicsLayoutItem *itemAt(int index) const override
virtual void removeAt(int index) override
virtual void setGeometry(const QRectF &rect) override
virtual QSizeF sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const override

상세 설명

QGraphicsGridLayout을 사용하는 가장 일반적인 방법은 힙에 객체를 생성하고, 생성자에 부모 위젯을 전달한 다음, ` addItem()`를 호출하여 위젯과 레이아웃을 추가하는 것입니다. QGraphicsGridLayout은 항목을 추가할 때마다 그리드의 크기를 자동으로 계산합니다.

QGraphicsScene scene;
QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);

QGraphicsWidget *form = new QGraphicsWidget;
scene.addItem(form);

QGraphicsGridLayout *layout = new QGraphicsGridLayout(form);
layout->addItem(textEdit, 0, 0);
layout->addItem(pushButton, 0, 1);

또는, 레이아웃의 생성자에 부모 위젯을 전달하지 않는 경우, QGraphicsWidget::setLayout()를 호출하여 이 레이아웃을 해당 위젯의 최상위 레이아웃으로 설정해야 하며, 위젯이 레이아웃에 대한 소유권을 갖게 됩니다.

레이아웃이 항목에 대한 소유권을 갖습니다. 레이아웃 항목이 QGraphicsItem 를 상속받는 경우(예: QGraphicsWidget)에는 레이아웃 항목이 두 개의 소유권 계층 구조에 속하게 되므로 소유권에 모호성이 발생할 수 있습니다. 이를 처리하는 방법은 QGraphicsLayoutItem::setOwnedByLayout() 문서를 참조하십시오. count() 및 itemAt()를 호출하여 레이아웃 내의 각 항목에 접근할 수 있습니다. removeAt()를 호출하면 항목을 파괴하지 않고 레이아웃에서 제거합니다.

QGraphicsGridLayout의 크기 힌트 및 크기 정책

QGraphicsGridLayout은 각 항목의 크기 힌트와 크기 정책을 따르며, 그리드의 셀에 항목이 채울 수 있는 공간보다 더 많은 공간이 있을 경우, 각 항목은 해당 항목에 대한 레이아웃의 정렬 방식에 따라 배열됩니다. setAlignment()를 호출하여 각 항목의 정렬 방식을 설정할 수 있으며, alignment()를 호출하여 항목의 정렬 방식을 확인할 수 있습니다. 또한 setRowAlignment() 및 setColumnAlignment()를 각각 호출하여 전체 행 또는 열의 정렬 방식을 설정할 수도 있습니다. 기본적으로 항목은 왼쪽 상단으로 정렬됩니다.

QGraphicsLinearLayout 및 QGraphicsWidget도 참조하십시오 .

멤버 함수 설명서

QGraphicsGridLayout::QGraphicsGridLayout(QGraphicsLayoutItem *parent = nullptr)

QGraphicsGridLayout 인스턴스를 생성합니다. ` parent `는 ` QGraphicsLayout`의 생성자에 전달됩니다.

[virtual noexcept] QGraphicsGridLayout::~QGraphicsGridLayout()

QGraphicsGridLayout 객체를 삭제합니다.

void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = Qt::Alignment())

row 및 column 의 그리드에 item 를 추가합니다. item 의 경우 선택 사항인 alignment 을 지정할 수 있습니다.

void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())

row 및 column 의 그리드에 item 를 추가합니다. rowSpan 와 columnSpan 를 지정할 수 있으며, 선택 사항으로 alignment 도 지정할 수 있습니다.

Qt::Alignment QGraphicsGridLayout::alignment(QGraphicsLayoutItem *item) const

item 의 정렬 방식을 반환합니다.

setAlignment()도 참조하십시오 .

Qt::Alignment QGraphicsGridLayout::columnAlignment(int column) const

column 의 정렬 방식을 반환합니다.

setColumnAlignment()도 참조하십시오 .

int QGraphicsGridLayout::columnCount() const

그리드 레이아웃의 열 수를 반환합니다. 이 값은 레이아웃 항목이 배치된 마지막 열의 인덱스보다 항상 1 더 큰 값입니다(마지막에 위치한 열을 제외하고 빈 열도 포함됩니다).

qreal QGraphicsGridLayout::columnMaximumWidth(int column) const

column 의 최대 너비를 반환합니다.

setColumnMaximumWidth()도 참조하십시오 .

qreal QGraphicsGridLayout::columnMinimumWidth(int column) const

column 의 최소 너비를 반환합니다.

setColumnMinimumWidth()도 참조하십시오 .

qreal QGraphicsGridLayout::columnPreferredWidth(int column) const

column 에 대한 권장 너비를 반환합니다.

setColumnPreferredWidth()도 참조하십시오 .

qreal QGraphicsGridLayout::columnSpacing(int column) const

column 의 열 간격을 반환합니다.

setColumnSpacing()도 참조하십시오 .

int QGraphicsGridLayout::columnStretchFactor(int column) const

column 에 대한 신장 계수를 반환합니다.

setColumnStretchFactor()도 참조하십시오 .

[override virtual] int QGraphicsGridLayout::count() const

QGraphicsLayout::count() const를 재구현합니다.

이 그리드 레이아웃에 포함된 레이아웃 항목의 개수를 반환합니다.

qreal QGraphicsGridLayout::horizontalSpacing() const

그리드 레이아웃의 기본 가로 간격을 반환합니다.

setHorizontalSpacing()도 참조하십시오 .

[override virtual] void QGraphicsGridLayout::invalidate()

QGraphicsLayout::invalidate() 메서드를 재구현합니다.

[override virtual] QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const

QGraphicsLayout::itemAt(int i) const를 재구현합니다.

index 에 있는 레이아웃 항목을 반환하며, 해당 인덱스에 레이아웃 항목이 없는 경우 nullptr 을 반환합니다.

QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const

(row, column) 위치에 있는 레이아웃 항목에 대한 포인터를 반환합니다.

[override virtual] void QGraphicsGridLayout::removeAt(int index)

QGraphicsLayout::removeAt(int index)를 재구현합니다.

index 에 있는 레이아웃 항목을 파괴하지 않고 제거합니다. 항목의 소유권은 호출자에게 이전됩니다.

addItem()도 참조하십시오 .

void QGraphicsGridLayout::removeItem(QGraphicsLayoutItem *item)

item 레이아웃 항목을 파기하지 않고 제거합니다. 해당 항목의 소유권이 호출자에게 이전됩니다.

addItem()도 참조하십시오 .

Qt::Alignment QGraphicsGridLayout::rowAlignment(int row) const

row 의 정렬 방식을 반환합니다.

setRowAlignment()도 참조하십시오 .

int QGraphicsGridLayout::rowCount() const

그리드 레이아웃의 행 수를 반환합니다. 이 값은 레이아웃 항목이 차지하고 있는 마지막 행의 인덱스보다 항상 1이 더 큰 값입니다(끝에 있는 빈 행을 제외하고는 빈 행도 포함됩니다).

qreal QGraphicsGridLayout::rowMaximumHeight(int row) const

row의 최대 높이를 반환합니다. row.

setRowMaximumHeight()도 참조하십시오 .

qreal QGraphicsGridLayout::rowMinimumHeight(int row) const

row의 최소 높이를 반환합니다. row.

setRowMinimumHeight()도 참조하십시오 .

qreal QGraphicsGridLayout::rowPreferredHeight(int row) const

row 의 row에 대한 권장 높이를 반환합니다.

setRowPreferredHeight()도 참조하십시오 .

qreal QGraphicsGridLayout::rowSpacing(int row) const

row 의 행 간격을 반환합니다.

setRowSpacing()도 참조하십시오 .

int QGraphicsGridLayout::rowStretchFactor(int row) const

row 의 신축 계수를 반환합니다.

setRowStretchFactor()도 참조하십시오 .

void QGraphicsGridLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)

item 의 정렬 방식을 alignment 로 설정합니다.

alignment()도 참조하십시오 .

void QGraphicsGridLayout::setColumnAlignment(int column, Qt::Alignment alignment)

column 의 정렬 방식을 alignment 로 설정합니다.

columnAlignment()도 참조하십시오 .

void QGraphicsGridLayout::setColumnFixedWidth(int column, qreal width)

column 의 고정 너비를 width 로 설정합니다.

void QGraphicsGridLayout::setColumnMaximumWidth(int column, qreal width)

column 의 최대 너비를 width 로 설정합니다.

columnMaximumWidth()도 참조하십시오 .

void QGraphicsGridLayout::setColumnMinimumWidth(int column, qreal width)

column 의 최소 너비를 width 로 설정합니다.

columnMinimumWidth()도 참조하십시오 .

void QGraphicsGridLayout::setColumnPreferredWidth(int column, qreal width)

column 의 기본 너비를 width 로 설정합니다.

columnPreferredWidth()도 참조하십시오 .

void QGraphicsGridLayout::setColumnSpacing(int column, qreal spacing)

column 의 간격을 spacing 로 설정합니다.

columnSpacing()도 참조하십시오 .

void QGraphicsGridLayout::setColumnStretchFactor(int column, int stretch)

column 의 스트레치 계수를 stretch 로 설정합니다.

columnStretchFactor()도 참조하십시오 .

[override virtual] void QGraphicsGridLayout::setGeometry(const QRectF &rect)

QGraphicsLayoutItem::setGeometry(const QRectF &rect)를 재구현합니다.

그리드 레이아웃의 경계 지오메트리를 rect 로 설정합니다.

void QGraphicsGridLayout::setHorizontalSpacing(qreal spacing)

그리드 레이아웃의 기본 가로 간격을 spacing 로 설정합니다.

horizontalSpacing()도 참조하십시오 .

void QGraphicsGridLayout::setRowAlignment(int row, Qt::Alignment alignment)

row 의 정렬을 alignment 로 설정합니다.

rowAlignment()도 참조하십시오 .

void QGraphicsGridLayout::setRowFixedHeight(int row, qreal height)

행의 고정 높이( row)를 height 로 설정합니다.

void QGraphicsGridLayout::setRowMaximumHeight(int row, qreal height)

행의 최대 높이( row)를 height 로 설정합니다.

rowMaximumHeight()도 참조하십시오 .

void QGraphicsGridLayout::setRowMinimumHeight(int row, qreal height)

행의 최소 높이( row)를 height 로 설정합니다.

rowMinimumHeight()도 참조하십시오 .

void QGraphicsGridLayout::setRowPreferredHeight(int row, qreal height)

행의 기본 높이( row)를 height 로 설정합니다.

rowPreferredHeight()도 참조하십시오 .

void QGraphicsGridLayout::setRowSpacing(int row, qreal spacing)

row 의 간격을 spacing 로 설정합니다.

rowSpacing()도 참조하십시오 .

void QGraphicsGridLayout::setRowStretchFactor(int row, int stretch)

row 의 신축 계수를 stretch 로 설정합니다.

rowStretchFactor()도 참조하십시오 .

void QGraphicsGridLayout::setSpacing(qreal spacing)

그리드 레이아웃의 기본 간격(수직 및 수평 모두)을 ‘ spacing ’로 설정합니다.

rowSpacing() 및 columnSpacing()도 참조하십시오 .

void QGraphicsGridLayout::setVerticalSpacing(qreal spacing)

그리드 레이아웃의 기본 수직 간격을 ` spacing`로 설정합니다.

verticalSpacing()도 참조하십시오 .

[override virtual] QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const

QGraphicsLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const를 재구현합니다.

qreal QGraphicsGridLayout::verticalSpacing() const

그리드 레이아웃의 기본 세로 간격을 반환합니다.

setVerticalSpacing()도 참조하십시오 .

© 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.