QGraphicsGridLayout Class
Die Klasse „QGraphicsGridLayout“ bietet ein Rasterlayout zur Verwaltung von Widgets in der Graphics View. Mehr...
| Header: | #include <QGraphicsGridLayout> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
| qmake: | QT += widgets |
| Erbt: | QGraphicsLayout |
Öffentliche Funktionen
| 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 |
Neu implementierte öffentliche Funktionen
| 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 |
Ausführliche Beschreibung
Die gängigste Art, QGraphicsGridLayout zu verwenden, besteht darin, ein Objekt im Heap zu erstellen, dem Konstruktor ein übergeordnetes Widget zu übergeben und anschließend Widgets und Layouts durch Aufruf von ` addItem()` hinzuzufügen. QGraphicsGridLayout berechnet die Abmessungen des Rasters automatisch, während Sie Elemente hinzufügen.
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);Alternativ müssen Sie, wenn Sie dem Konstruktor des Layouts kein übergeordnetes Widget übergeben, ` QGraphicsWidget::setLayout()` aufrufen, um dieses Layout als oberstes Layout für dieses Widget festzulegen; das Widget übernimmt dann die Verantwortung für das Layout.
Das Layout übernimmt die Eigentumsrechte an den Elementen. In einigen Fällen, in denen das Layout-Element ebenfalls von QGraphicsItem erbt (z. B. QGraphicsWidget), kommt es zu einer Mehrdeutigkeit bei den Eigentumsrechten, da das Layout-Element zwei Eigentums-Hierarchien angehört. Informationen zur Behandlung dieses Problems finden Sie in der Dokumentation zu ` QGraphicsLayoutItem::setOwnedByLayout()`. Sie können auf jedes Element im Layout zugreifen, indem Sie ` count()` und ` itemAt()` aufrufen. Der Aufruf von ` removeAt()` entfernt ein Element aus dem Layout, ohne es zu zerstören.
Größenhinweise und Größenrichtlinien in `QGraphicsGridLayout`
QGraphicsGridLayout berücksichtigt die Größenhinweise und Größenrichtlinien jedes Elements. Wenn eine Zelle im Raster mehr Platz bietet, als die Elemente ausfüllen können, wird jedes Element entsprechend der Ausrichtung des Layouts für dieses Element angeordnet. Sie können für jedes Element eine Ausrichtung festlegen, indem Sie ` setAlignment()` aufrufen, und die Ausrichtung eines beliebigen Elements überprüfen, indem Sie ` alignment()` aufrufen. Sie können die Ausrichtung auch für eine gesamte Zeile oder Spalte festlegen, indem Sie ` setRowAlignment()` bzw. ` setColumnAlignment()` aufrufen. Standardmäßig werden Elemente links oben ausgerichtet.
Siehe auch QGraphicsLinearLayout und QGraphicsWidget.
Dokumentation zu den Member-Funktionen
QGraphicsGridLayout::QGraphicsGridLayout(QGraphicsLayoutItem *parent = nullptr)
Erstellt eine Instanz von `QGraphicsGridLayout`. ` parent ` wird an den Konstruktor von ` QGraphicsLayout` übergeben.
[virtual noexcept] QGraphicsGridLayout::~QGraphicsGridLayout()
Löscht das „ QGraphicsGridLayout “-Objekt.
void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = Qt::Alignment())
Fügt „ item “ zur Tabelle auf row und column hinzu. Sie können optional „ alignment “ für item angeben.
void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())
Fügt „ item “ zum Raster auf row und column hinzu. Sie können rowSpan und columnSpan sowie optional alignment angeben.
Qt::Alignment QGraphicsGridLayout::alignment(QGraphicsLayoutItem *item) const
Gibt die Ausrichtung für item zurück.
Siehe auch setAlignment().
Qt::Alignment QGraphicsGridLayout::columnAlignment(int column) const
Gibt die Ausrichtung für column zurück.
Siehe auch setColumnAlignment().
int QGraphicsGridLayout::columnCount() const
Gibt die Anzahl der Spalten im Rasterlayout zurück. Diese ist immer um eins größer als der Index der letzten Spalte, die von einem Layoutelement belegt ist (leere Spalten werden mitgezählt, mit Ausnahme derjenigen am Ende).
qreal QGraphicsGridLayout::columnMaximumWidth(int column) const
Gibt die maximale Breite für „ column “ zurück.
Siehe auch setColumnMaximumWidth().
qreal QGraphicsGridLayout::columnMinimumWidth(int column) const
Gibt die minimale Breite für column zurück.
Siehe auch setColumnMinimumWidth().
qreal QGraphicsGridLayout::columnPreferredWidth(int column) const
Gibt die bevorzugte Breite für „ column “ zurück.
Siehe auch setColumnPreferredWidth().
qreal QGraphicsGridLayout::columnSpacing(int column) const
Gibt den Spaltenabstand für column zurück.
Siehe auch setColumnSpacing().
int QGraphicsGridLayout::columnStretchFactor(int column) const
Gibt den Stretch-Faktor für „ column “ zurück.
Siehe auch ` setColumnStretchFactor()`.
[override virtual] int QGraphicsGridLayout::count() const
Implementiert neu: ` QGraphicsLayout::count()` const.
Gibt die Anzahl der Layout-Elemente in diesem Rasterlayout zurück.
qreal QGraphicsGridLayout::horizontalSpacing() const
Gibt den Standard-Horizontalabstand für das Rasterlayout zurück.
Siehe auch ` setHorizontalSpacing()`.
[override virtual] void QGraphicsGridLayout::invalidate()
Implementiert: QGraphicsLayout::invalidate().
[override virtual] QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const
Implementiert: ` QGraphicsLayout::itemAt(int i) const`.
Gibt das Layout-Element unter index zurück oder nullptr, falls unter diesem Index kein Layout-Element vorhanden ist.
QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const
Gibt einen Zeiger auf das Layout-Element an der Position (row, column) zurück.
[override virtual] void QGraphicsGridLayout::removeAt(int index)
Implementiert: QGraphicsLayout::removeAt(int index).
Entfernt das Layout-Element unter index, ohne es zu zerstören. Die Eigentumsrechte an dem Element werden auf den Aufrufer übertragen.
Siehe auch ` addItem()`.
void QGraphicsGridLayout::removeItem(QGraphicsLayoutItem *item)
Entfernt das Layout-Element „ item “, ohne es zu löschen. Die Eigentumsrechte an dem Element werden auf den Aufrufer übertragen.
Siehe auch addItem().
Qt::Alignment QGraphicsGridLayout::rowAlignment(int row) const
Gibt die Ausrichtung von row zurück.
Siehe auch setRowAlignment().
int QGraphicsGridLayout::rowCount() const
Gibt die Anzahl der Zeilen im Rasterlayout zurück. Diese ist immer um eins größer als der Index der letzten Zeile, die von einem Layoutelement belegt ist (leere Zeilen werden mitgezählt, mit Ausnahme derjenigen am Ende).
qreal QGraphicsGridLayout::rowMaximumHeight(int row) const
Gibt die maximale Höhe für die Zeile zurück, row.
Siehe auch setRowMaximumHeight().
qreal QGraphicsGridLayout::rowMinimumHeight(int row) const
Gibt die minimale Höhe für die Zeile zurück, row.
Siehe auch setRowMinimumHeight().
qreal QGraphicsGridLayout::rowPreferredHeight(int row) const
Gibt die bevorzugte Höhe für die Zeile zurück, row.
Siehe auch ` setRowPreferredHeight()`.
qreal QGraphicsGridLayout::rowSpacing(int row) const
Gibt den Zeilenabstand für „ row “ zurück.
Siehe auch setRowSpacing().
int QGraphicsGridLayout::rowStretchFactor(int row) const
Gibt den Stretch-Faktor für „ row “ zurück.
Siehe auch ` setRowStretchFactor()`.
void QGraphicsGridLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
Legt die Ausrichtung für „ item “ auf „ alignment “ fest.
Siehe auch alignment().
void QGraphicsGridLayout::setColumnAlignment(int column, Qt::Alignment alignment)
Legt die Ausrichtung für „ column “ auf „ alignment “ fest.
Siehe auch columnAlignment().
void QGraphicsGridLayout::setColumnFixedWidth(int column, qreal width)
Legt die feste Breite von „ column “ auf „ width “ fest.
void QGraphicsGridLayout::setColumnMaximumWidth(int column, qreal width)
Legt die maximale Breite von „ column “ auf „ width “ fest.
Siehe auch columnMaximumWidth().
void QGraphicsGridLayout::setColumnMinimumWidth(int column, qreal width)
Legt die Mindestbreite für column auf width fest.
Siehe auch columnMinimumWidth().
void QGraphicsGridLayout::setColumnPreferredWidth(int column, qreal width)
Legt die bevorzugte Breite für column auf width fest.
Siehe auch columnPreferredWidth().
void QGraphicsGridLayout::setColumnSpacing(int column, qreal spacing)
Legt den Abstand für „ column “ auf „ spacing “ fest.
Siehe auch columnSpacing().
void QGraphicsGridLayout::setColumnStretchFactor(int column, int stretch)
Legt den Stretch-Faktor für „ column “ auf „ stretch “ fest.
Siehe auch columnStretchFactor().
[override virtual] void QGraphicsGridLayout::setGeometry(const QRectF &rect)
Umsetzt: ` QGraphicsLayoutItem::setGeometry` (`const QRectF &rect`).
Setzt die Begrenzungsgeometrie des Rasterlayouts auf ` rect`.
void QGraphicsGridLayout::setHorizontalSpacing(qreal spacing)
Legt den Standard-Horizontalabstand für das Rasterlayout auf „ spacing “ fest.
Siehe auch ` horizontalSpacing()`.
void QGraphicsGridLayout::setRowAlignment(int row, Qt::Alignment alignment)
Legt die Ausrichtung von „ row “ auf „ alignment “ fest.
Siehe auch rowAlignment().
void QGraphicsGridLayout::setRowFixedHeight(int row, qreal height)
Legt die feste Höhe für die Zeile „ row “ auf „ height “ fest.
void QGraphicsGridLayout::setRowMaximumHeight(int row, qreal height)
Legt die maximale Höhe für die Zeile „ row “ auf „ height “ fest.
Siehe auch rowMaximumHeight().
void QGraphicsGridLayout::setRowMinimumHeight(int row, qreal height)
Legt die Mindesthöhe für die Zeile „ row “ auf „ height “ fest.
Siehe auch „ rowMinimumHeight()“.
void QGraphicsGridLayout::setRowPreferredHeight(int row, qreal height)
Legt die bevorzugte Höhe für die Zeile „ row “ auf „ height “ fest.
Siehe auch ` rowPreferredHeight()`.
void QGraphicsGridLayout::setRowSpacing(int row, qreal spacing)
Legt den Abstand für „ row “ auf „ spacing “ fest.
Siehe auch rowSpacing().
void QGraphicsGridLayout::setRowStretchFactor(int row, int stretch)
Legt den Stretch-Faktor für „ row “ auf „ stretch “ fest.
Siehe auch rowStretchFactor().
void QGraphicsGridLayout::setSpacing(qreal spacing)
Legt den Standardabstand des Rasterlayouts – sowohl vertikal als auch horizontal – auf „ spacing “ fest.
Siehe auch „ rowSpacing()“ und „ columnSpacing()“.
void QGraphicsGridLayout::setVerticalSpacing(qreal spacing)
Legt den Standard-Vertikalabstand für das Rasterlayout auf „ spacing “ fest.
Siehe auch ` verticalSpacing()`.
[override virtual] QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
Implementiert neu: ` QGraphicsLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const`.
qreal QGraphicsGridLayout::verticalSpacing() const
Gibt den Standard-Vertikalabstand für das Rasterlayout zurück.
Siehe auch „ 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.