QGraphicsGridLayout Class
Die Klasse QGraphicsGridLayout bietet ein Grid-Layout für die Verwaltung von Widgets in der Grafikansicht. Mehr...
Kopfzeile: | #include <QGraphicsGridLayout> |
CMake: | find_package(Qt6 REQUIRED COMPONENTS Widgets) target_link_libraries(mytarget PRIVATE Qt6::Widgets) |
qmake: | QT += widgets |
Vererbt: | 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 |
Reimplementierte ö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 |
Detaillierte Beschreibung
Die gebräuchlichste Art, QGraphicsGridLayout zu verwenden, besteht darin, ein Objekt auf dem Heap zu konstruieren, dem Konstruktor ein übergeordnetes Widget zu übergeben und dann Widgets und Layouts durch den Aufruf von addItem() hinzuzufügen. QGraphicsGridLayout berechnet automatisch die Dimensionen des Gitters, 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);
Wenn Sie kein übergeordnetes Widget an den Konstruktor des Layouts übergeben, müssen Sie alternativ QGraphicsWidget::setLayout() aufrufen, um dieses Layout als oberstes Layout für dieses Widget festzulegen, und das Widget wird Eigentümer des Layouts.
Das Layout übernimmt das Eigentum an den Elementen. In einigen Fällen, in denen das Layoutelement auch von QGraphicsItem erbt (z. B. QGraphicsWidget), kommt es zu einer Mehrdeutigkeit bei der Eigentümerschaft, da das Layoutelement zu zwei Eigentümerhierarchien gehört. Siehe die Dokumentation von QGraphicsLayoutItem::setOwnedByLayout(), wie dies zu handhaben ist. 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 respektiert die Größenhinweise und Größenrichtlinien jedes Elements. Wenn eine Zelle im Raster mehr Platz hat, als die Elemente füllen können, wird jedes Element entsprechend der Ausrichtung des Layouts für dieses Element angeordnet. Sie können eine Ausrichtung für jedes Element festlegen, indem Sie setAlignment() aufrufen, und die Ausrichtung für jedes Element überprüfen, indem Sie alignment() aufrufen. Sie können auch die Ausrichtung für eine ganze Zeile oder Spalte festlegen, indem Sie setRowAlignment() bzw. setColumnAlignment() aufrufen. Standardmäßig werden die Elemente oben links ausgerichtet.
Siehe auch QGraphicsLinearLayout und QGraphicsWidget.
Dokumentation der Mitgliedsfunktionen
QGraphicsGridLayout::QGraphicsGridLayout(QGraphicsLayoutItem *parent = nullptr)
Konstruiert eine QGraphicsGridLayout-Instanz. parent wird an den Konstruktor von QGraphicsLayout übergeben.
[virtual noexcept]
QGraphicsGridLayout::~QGraphicsGridLayout()
Zerstört das Objekt QGraphicsGridLayout.
void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = Qt::Alignment())
Fügt item in das Raster auf row und column ein. 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 in das Raster auf row und column ein. 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 Grid-Layout zurück. Dies ist immer eine mehr als der Index der letzten Spalte, die von einem Layoutelement belegt ist (leere Spalten werden gezählt, außer denen 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 Mindestbreite 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 Streckungsfaktor für column zurück.
Siehe auch setColumnStretchFactor().
[override virtual]
int QGraphicsGridLayout::count() const
Reimplements: QGraphicsLayout::count() const.
Gibt die Anzahl der Layoutelemente in diesem Rasterlayout zurück.
qreal QGraphicsGridLayout::horizontalSpacing() const
Gibt den standardmäßigen horizontalen Abstand für das Rasterlayout zurück.
Siehe auch setHorizontalSpacing().
[override virtual]
void QGraphicsGridLayout::invalidate()
Reimplements: QGraphicsLayout::invalidate().
[override virtual]
QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const
Reimplements: QGraphicsLayout::itemAt(int i) const.
Gibt das Layoutelement an index zurück, oder nullptr
, wenn es kein Layoutelement an diesem Index gibt.
QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const
Gibt einen Zeiger auf das Layoutelement an (row, column) zurück.
[override virtual]
void QGraphicsGridLayout::removeAt(int index)
Reimplements: QGraphicsLayout::removeAt(int index).
Entfernt das Layoutelement unter index, ohne es zu zerstören. Das Eigentum an dem Element geht auf den Aufrufer über.
Siehe auch addItem().
void QGraphicsGridLayout::removeItem(QGraphicsLayoutItem *item)
Entfernt das Layoutelement item, ohne es zu zerstören. Das Eigentum an dem Element geht auf den Aufrufer über.
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. Dies ist immer eine Zeile mehr als der Index der letzten Zeile, die von einem Layoutelement belegt ist (leere Zeilen werden gezählt, mit Ausnahme derjenigen am Ende).
qreal QGraphicsGridLayout::rowMaximumHeight(int row) const
Gibt die maximale Höhe für die Zeile row zurück.
Siehe auch setRowMaximumHeight().
qreal QGraphicsGridLayout::rowMinimumHeight(int row) const
Gibt die Mindesthöhe für die Zeile row zurück.
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 Streckungsfaktor für row zurück.
Siehe auch setRowStretchFactor().
void QGraphicsGridLayout::setAlignment(QGraphicsLayoutItem *item, Qt::Alignment alignment)
Setzt die Ausrichtung für item auf alignment.
Siehe auch alignment().
void QGraphicsGridLayout::setColumnAlignment(int column, Qt::Alignment alignment)
Setzt die Ausrichtung für column auf alignment.
Siehe auch columnAlignment().
void QGraphicsGridLayout::setColumnFixedWidth(int column, qreal width)
Setzt die feste Breite von column auf width.
void QGraphicsGridLayout::setColumnMaximumWidth(int column, qreal width)
Setzt die maximale Breite von column auf width.
Siehe auch columnMaximumWidth().
void QGraphicsGridLayout::setColumnMinimumWidth(int column, qreal width)
Setzt die Mindestbreite für column auf width.
Siehe auch columnMinimumWidth().
void QGraphicsGridLayout::setColumnPreferredWidth(int column, qreal width)
Setzt die bevorzugte Breite für column auf width.
Siehe auch columnPreferredWidth().
void QGraphicsGridLayout::setColumnSpacing(int column, qreal spacing)
Setzt den Abstand für column auf spacing.
Siehe auch columnSpacing().
void QGraphicsGridLayout::setColumnStretchFactor(int column, int stretch)
Setzt den Streckungsfaktor für column auf stretch.
Siehe auch columnStretchFactor().
[override virtual]
void QGraphicsGridLayout::setGeometry(const QRectF &rect)
Reimplements: QGraphicsLayoutItem::setGeometry(const QRectF &rect).
Setzt die Begrenzungsgeometrie des Rasterlayouts auf rect.
void QGraphicsGridLayout::setHorizontalSpacing(qreal spacing)
Setzt den horizontalen Standardabstand für das Rasterlayout auf spacing.
Siehe auch horizontalSpacing().
void QGraphicsGridLayout::setRowAlignment(int row, Qt::Alignment alignment)
Setzt die Ausrichtung von row auf alignment.
Siehe auch rowAlignment().
void QGraphicsGridLayout::setRowFixedHeight(int row, qreal height)
Setzt die feste Höhe für die Zeile row auf height.
void QGraphicsGridLayout::setRowMaximumHeight(int row, qreal height)
Setzt die maximale Höhe der Zeile row auf height.
Siehe auch rowMaximumHeight().
void QGraphicsGridLayout::setRowMinimumHeight(int row, qreal height)
Setzt die Mindesthöhe für die Zeile row auf height.
Siehe auch rowMinimumHeight().
void QGraphicsGridLayout::setRowPreferredHeight(int row, qreal height)
Setzt die bevorzugte Höhe für die Zeile row auf height.
Siehe auch rowPreferredHeight().
void QGraphicsGridLayout::setRowSpacing(int row, qreal spacing)
Setzt den Abstand für row auf spacing.
Siehe auch rowSpacing().
void QGraphicsGridLayout::setRowStretchFactor(int row, int stretch)
Setzt den Streckungsfaktor für row auf stretch.
Siehe auch rowStretchFactor().
void QGraphicsGridLayout::setSpacing(qreal spacing)
Setzt die Standardabstände des Rasterlayouts, sowohl vertikal als auch horizontal, auf spacing.
Siehe auch rowSpacing() und columnSpacing().
void QGraphicsGridLayout::setVerticalSpacing(qreal spacing)
Setzt den vertikalen Standardabstand für das Rasterlayout auf spacing.
Siehe auch verticalSpacing().
[override virtual]
QSizeF QGraphicsGridLayout::sizeHint(Qt::SizeHint which, const QSizeF &constraint = QSizeF()) const
Reimplements: QGraphicsLayoutItem::sizeHint(Qt::SizeHint which, const QSizeF &constraint) const.
qreal QGraphicsGridLayout::verticalSpacing() const
Gibt den vertikalen Standardabstand für das Rasterlayout zurück.
Siehe auch setVerticalSpacing().
© 2025 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.