Класс QGraphicsGridLayout
Класс QGraphicsGridLayout предоставляет структуру сетки для управления виджетами в представлении Graphics View. Подробнее...
| Заголовок: | #include <QGraphicsGridLayout> |
| CMake: | find_package(Qt6 COMPONENTS Widgets REQUIRED) 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, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment()) |
| void | addItem(QGraphicsLayoutItem *item, int row, int column, 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() и, наконец, назначении макета виджету с помощью вызова QGraphicsWidget::setLayout(). QGraphicsGridLayout автоматически вычисляет размеры сетки по мере добавления элементов.
QGraphicsScene scene; QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit); QGraphicsWidget *pushButton = scene.addWidget(new QPushButton); QGraphicsGridLayout *layout = new QGraphicsGridLayout; layout->addItem(textEdit, 0, 0); layout->addItem(pushButton, 0, 1); QGraphicsWidget *form = new QGraphicsWidget; form->setLayout(layout); scene.addItem(form);
Макет принимает на себя владение элементами. В некоторых случаях, когда элемент макета также наследуется от QGraphicsItem (например, QGraphicsWidget), возникает неоднозначность с владение, так как элемент макета принадлежит двум иерархиям владения. Обратитесь к документации QGraphicsLayoutItem::setOwnedByLayout(), чтобы узнать, как с этим справиться. Вы можете получить доступ к каждому элементу в макете, вызвав count() и itemAt(). Вызов removeAt() удалит элемент из макета без его уничтожения.
Рекомендации по размеру и политики размеров в QGraphicsGridLayout
QGraphicsGridLayout учитывает рекомендации по размеру и политики размеров каждого элемента, и когда ячейка в сетке имеет больше места, чем могут заполнить элементы, каждый элемент располагается в соответствии с выравниванием макета для этого элемента. Вы можете установить выравнивание для каждого элемента, вызвав setAlignment(), и проверить выравнивание любого элемента, вызвав alignment(). Вы также можете установить выравнивание для всего ряда или столбца, вызвав setRowAlignment() и setColumnAlignment() соответственно. По умолчанию элементы выравниваются по верхнему левому углу.
См. также QGraphicsLinearLayout и QGraphicsWidget.
Документация по членам функций
QGraphicsGridLayout::QGraphicsGridLayout(QGraphicsLayoutItem *parent = nullptr)
Создаёт экземпляр QGraphicsGridLayout. parent передаётся в конструктор QGraphicsLayout.
[virtual] QGraphicsGridLayout::~QGraphicsGridLayout()
Уничтожает объект QGraphicsGridLayout.
void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment = Qt::Alignment())
Добавляет item в сетку по row и column. Вы можете указать rowSpan и columnSpan и необязательное alignment.
void QGraphicsGridLayout::addItem(QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment = Qt::Alignment())
Добавляет item в сетку по row и column. Вы можете указать необязательное alignment для item.
Qt::Alignment QGraphicsGridLayout::alignment(QGraphicsLayoutItem *item) const
Возвращает выравнивание для item.
См. также setAlignment().
Qt::Alignment QGraphicsGridLayout::columnAlignment(int column) const
Возвращает выравнивание для column.
См. также setColumnAlignment().
int QGraphicsGridLayout::columnCount() const
Возвращает количество столбцов в сетке макета. Это всегда на единицу больше индекса последнего столбца, занятого элементом макета (пустые столбцы учитываются, кроме тех, которые находятся в конце).
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().
QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int row, int column) const
Возвращает указатель на элемент макета в (row, column).
[override virtual] QGraphicsLayoutItem *QGraphicsGridLayout::itemAt(int index) const
Реализует: QGraphicsLayout::itemAt(int i) const.
Возвращает элемент макета по индексу index или nullptr, если элемента макета по этому индексу нет.
[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
Возвращает количество строк в сетке макета. Это всегда на единицу больше индекса последней строки, занятой элементом макета (пустые строки учитываются, кроме тех, которые находятся в конце).
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().
© The Qt Company Ltd
Licensed under the GNU Free Documentation License, Version 1.3.
https://doc.qt.io/qt-6.0/qgraphicsgridlayout.html