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 など)、そのレイアウト項目は2つの所有権階層に属することになるため、所有権に曖昧さが生じることがあります。 この処理方法については、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 。
setRowMaximumHeight()も参照してください 。
qreal QGraphicsGridLayout::rowMinimumHeight(int row) const
行の最小高さを返します。row 。
setRowMinimumHeight()も参照してください 。
qreal QGraphicsGridLayout::rowPreferredHeight(int row) const
行の推奨高さを返します。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.