Qt 4.8
Public Functions | List of all members
QGraphicsGridLayout Class Reference

The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View. More...

#include <qgraphicsgridlayout.h>

Inheritance diagram for QGraphicsGridLayout:
QGraphicsLayout QGraphicsLayoutItem

Public Functions

void addItem (QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment=0)
 Adds item to the grid on row and column. More...
 
void addItem (QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment=0)
 Adds item to the grid on row and column. More...
 
Qt::Alignment alignment (QGraphicsLayoutItem *item) const
 Returns the alignment for item. More...
 
Qt::Alignment columnAlignment (int column) const
 Returns the alignment for column. More...
 
int columnCount () const
 Returns the number of columns in the grid layout. More...
 
qreal columnMaximumWidth (int column) const
 Returns the maximum width for column. More...
 
qreal columnMinimumWidth (int column) const
 Returns the minimum width for column. More...
 
qreal columnPreferredWidth (int column) const
 Returns the preferred width for column. More...
 
qreal columnSpacing (int column) const
 Returns the column spacing for column. More...
 
int columnStretchFactor (int column) const
 Returns the stretch factor for column. More...
 
int count () const
 Returns the number of layout items in this grid layout. More...
 
qreal horizontalSpacing () const
 Returns the default horizontal spacing for the grid layout. More...
 
void invalidate ()
 Reimplemented Function More...
 
QGraphicsLayoutItemitemAt (int row, int column) const
 Returns a pointer to the layout item at (row, column). More...
 
QGraphicsLayoutItemitemAt (int index) const
 Returns the layout item at index, or 0 if there is no layout item at this index. More...
 
 QGraphicsGridLayout (QGraphicsLayoutItem *parent=0)
 Constructs a QGraphicsGridLayout instance. More...
 
void removeAt (int index)
 Removes the layout item at index without destroying it. More...
 
void removeItem (QGraphicsLayoutItem *item)
 Removes the layout item item without destroying it. More...
 
Qt::Alignment rowAlignment (int row) const
 Returns the alignment of row. More...
 
int rowCount () const
 Returns the number of rows in the grid layout. More...
 
qreal rowMaximumHeight (int row) const
 Returns the maximum height for row, row. More...
 
qreal rowMinimumHeight (int row) const
 Returns the minimum height for row, row. More...
 
qreal rowPreferredHeight (int row) const
 Returns the preferred height for row, row. More...
 
qreal rowSpacing (int row) const
 Returns the row spacing for row. More...
 
int rowStretchFactor (int row) const
 Returns the stretch factor for row. More...
 
void setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment)
 Sets the alignment for item to alignment. More...
 
void setColumnAlignment (int column, Qt::Alignment alignment)
 Sets the alignment for column to alignment. More...
 
void setColumnFixedWidth (int column, qreal width)
 Sets the fixed width of column to width. More...
 
void setColumnMaximumWidth (int column, qreal width)
 Sets the maximum width of column to width. More...
 
void setColumnMinimumWidth (int column, qreal width)
 Sets the minimum width for column to width. More...
 
void setColumnPreferredWidth (int column, qreal width)
 Sets the preferred width for column to width. More...
 
void setColumnSpacing (int column, qreal spacing)
 Sets the spacing for column to spacing. More...
 
void setColumnStretchFactor (int column, int stretch)
 Sets the stretch factor for column to stretch. More...
 
void setGeometry (const QRectF &rect)
 Sets the bounding geometry of the grid layout to rect. More...
 
void setHorizontalSpacing (qreal spacing)
 Sets the default horizontal spacing for the grid layout to spacing. More...
 
void setRowAlignment (int row, Qt::Alignment alignment)
 Sets the alignment of row to alignment. More...
 
void setRowFixedHeight (int row, qreal height)
 Sets the fixed height for row, row, to height. More...
 
void setRowMaximumHeight (int row, qreal height)
 Sets the maximum height for row, row, to height. More...
 
void setRowMinimumHeight (int row, qreal height)
 Sets the minimum height for row, row, to height. More...
 
void setRowPreferredHeight (int row, qreal height)
 Sets the preferred height for row, row, to height. More...
 
void setRowSpacing (int row, qreal spacing)
 Sets the spacing for row to spacing. More...
 
void setRowStretchFactor (int row, int stretch)
 Sets the stretch factor for row to stretch. More...
 
void setSpacing (qreal spacing)
 Sets the grid layout's default spacing, both vertical and horizontal, to spacing. More...
 
void setVerticalSpacing (qreal spacing)
 Sets the default vertical spacing for the grid layout to spacing. More...
 
QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 Reimplemented Function More...
 
qreal verticalSpacing () const
 Returns the default vertical spacing for the grid layout. More...
 
virtual ~QGraphicsGridLayout ()
 Destroys the QGraphicsGridLayout object. More...
 
- Public Functions inherited from QGraphicsLayout
void activate ()
 Activates the layout, causing all items in the layout to be immediately rearranged. More...
 
void getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const
 Reimplemented Function More...
 
bool isActivated () const
 Returns true if the layout is currently being activated; otherwise, returns false. More...
 
 QGraphicsLayout (QGraphicsLayoutItem *parent=0)
 Contructs a QGraphicsLayout object. More...
 
void setContentsMargins (qreal left, qreal top, qreal right, qreal bottom)
 Sets the contents margins to left, top, right and bottom. More...
 
virtual void updateGeometry ()
 Reimplemented Function More...
 
virtual void widgetEvent (QEvent *e)
 This virtual event handler receives all events for the managed widget. More...
 
 ~QGraphicsLayout ()
 Destroys the QGraphicsLayout object. More...
 
- Public Functions inherited from QGraphicsLayoutItem
QRectF contentsRect () const
 Returns the contents rect in local coordinates. More...
 
QSizeF effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 Returns the effective size hint for this QGraphicsLayoutItem. More...
 
QRectF geometry () const
 Returns the item's geometry (e. More...
 
QGraphicsItemgraphicsItem () const
 Returns the QGraphicsItem that this layout item represents. More...
 
bool isLayout () const
 Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges other QGraphicsLayoutItem objects); otherwise returns false. More...
 
qreal maximumHeight () const
 Returns the maximum height. More...
 
QSizeF maximumSize () const
 Returns the maximum size. More...
 
qreal maximumWidth () const
 Returns the maximum width. More...
 
qreal minimumHeight () const
 Returns the minimum height. More...
 
QSizeF minimumSize () const
 Returns the minimum size. More...
 
qreal minimumWidth () const
 Returns the minimum width. More...
 
bool ownedByLayout () const
 Returns whether a layout should delete this item in its destructor. More...
 
QGraphicsLayoutItemparentLayoutItem () const
 Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not inherit from QGraphicsLayoutItem (QGraphicsLayoutItem is often used through multiple inheritance with QObject-derived classes). More...
 
qreal preferredHeight () const
 Returns the preferred height. More...
 
QSizeF preferredSize () const
 Returns the preferred size. More...
 
qreal preferredWidth () const
 Returns the preferred width. More...
 
 QGraphicsLayoutItem (QGraphicsLayoutItem *parent=0, bool isLayout=false)
 Constructs the QGraphicsLayoutItem object. More...
 
void setMaximumHeight (qreal height)
 Sets the maximum height to height. More...
 
void setMaximumSize (const QSizeF &size)
 Sets the maximum size to size. More...
 
void setMaximumSize (qreal w, qreal h)
 This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)). More...
 
void setMaximumWidth (qreal width)
 Sets the maximum width to width. More...
 
void setMinimumHeight (qreal height)
 Sets the minimum height to height. More...
 
void setMinimumSize (const QSizeF &size)
 Sets the minimum size to size. More...
 
void setMinimumSize (qreal w, qreal h)
 This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)). More...
 
void setMinimumWidth (qreal width)
 Sets the minimum width to width. More...
 
void setParentLayoutItem (QGraphicsLayoutItem *parent)
 Sets the parent of this QGraphicsLayoutItem to parent. More...
 
void setPreferredHeight (qreal height)
 Sets the preferred height to height. More...
 
void setPreferredSize (const QSizeF &size)
 Sets the preferred size to size. More...
 
void setPreferredSize (qreal w, qreal h)
 This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)). More...
 
void setPreferredWidth (qreal width)
 Sets the preferred width to width. More...
 
void setSizePolicy (const QSizePolicy &policy)
 Sets the size policy to policy. More...
 
void setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType)
 This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)). More...
 
QSizePolicy sizePolicy () const
 Returns the current size policy. More...
 
virtual ~QGraphicsLayoutItem ()
 Destroys the QGraphicsLayoutItem object. More...
 

Additional Inherited Members

- Static Public Functions inherited from QGraphicsLayout
static bool instantInvalidatePropagation ()
 
static void setInstantInvalidatePropagation (bool enable)
 
- Protected Functions inherited from QGraphicsLayout
void addChildLayoutItem (QGraphicsLayoutItem *layoutItem)
 This function is a convenience function provided for custom layouts, and will go through all items in the layout and reparent their graphics items to the closest QGraphicsWidget ancestor of the layout. More...
 
 QGraphicsLayout (QGraphicsLayoutPrivate &, QGraphicsLayoutItem *)
 
- Protected Functions inherited from QGraphicsLayoutItem
 QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd)
 
void setGraphicsItem (QGraphicsItem *item)
 If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value. More...
 
void setOwnedByLayout (bool ownedByLayout)
 Sets whether a layout should delete this item in its destructor or not. More...
 
- Protected Variables inherited from QGraphicsLayoutItem
QScopedPointer< QGraphicsLayoutItemPrivated_ptr
 

Detailed Description

The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View.

Since
4.4

The most common way to use QGraphicsGridLayout is to construct an object on the heap with no parent, add widgets and layouts by calling addItem(), and finally assign the layout to a widget by calling QGraphicsWidget::setLayout(). QGraphicsGridLayout automatically computes the dimensions of the grid as you add items.

QGraphicsWidget *textEdit = scene.addWidget(new QTextEdit);
QGraphicsWidget *pushButton = scene.addWidget(new QPushButton);
layout->addItem(textEdit, 0, 0);
layout->addItem(pushButton, 0, 1);
form->setLayout(layout);
scene.addItem(form);

The layout takes ownership of the items. In some cases when the layout item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle this. You can access each item in the layout by calling count() and itemAt(). Calling removeAt() will remove an item from the layout, without destroying it.

Size Hints and Size Policies in QGraphicsGridLayout

QGraphicsGridLayout respects each item's size hints and size policies, and when a cell in the grid has more space than the items can fill, each item is arranged according to the layout's alignment for that item. You can set an alignment for each item by calling setAlignment(), and check the alignment for any item by calling alignment(). You can also set the alignment for an entire row or column by calling setRowAlignment() and setColumnAlignment() respectively. By default, items are aligned to the top left.

See also
QGraphicsLinearLayout, QGraphicsWidget

Definition at line 58 of file qgraphicsgridlayout.h.

Constructors and Destructors

◆ QGraphicsGridLayout()

QGraphicsGridLayout::QGraphicsGridLayout ( QGraphicsLayoutItem parent = 0)

Constructs a QGraphicsGridLayout instance.

parent is passed to QGraphicsLayout's constructor.

Definition at line 124 of file qgraphicsgridlayout.cpp.

126 {
127 }
QGraphicsLayout(QGraphicsLayoutItem *parent=0)
Contructs a QGraphicsLayout object.

◆ ~QGraphicsGridLayout()

QGraphicsGridLayout::~QGraphicsGridLayout ( )
virtual

Destroys the QGraphicsGridLayout object.

Definition at line 132 of file qgraphicsgridlayout.cpp.

133 {
134  for (int i = count() - 1; i >= 0; --i) {
135  QGraphicsLayoutItem *item = itemAt(i);
136  // The following lines can be removed, but this removes the item
137  // from the layout more efficiently than the implementation of
138  // ~QGraphicsLayoutItem.
139  removeAt(i);
140  if (item) {
141  item->setParentLayoutItem(0);
142  if (item->ownedByLayout())
143  delete item;
144  }
145  }
146 }
void setParentLayoutItem(QGraphicsLayoutItem *parent)
Sets the parent of this QGraphicsLayoutItem to parent.
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
bool ownedByLayout() const
Returns whether a layout should delete this item in its destructor.
int count() const
Returns the number of layout items in this grid layout.
void removeAt(int index)
Removes the layout item at index without destroying it.
QGraphicsLayoutItem * itemAt(int row, int column) const
Returns a pointer to the layout item at (row, column).

Functions

◆ addItem() [1/2]

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

Adds item to the grid on row and column.

You can specify a rowSpan and columnSpan and an optional alignment.

Definition at line 152 of file qgraphicsgridlayout.cpp.

154 {
156  if (row < 0 || column < 0) {
157  qWarning("QGraphicsGridLayout::addItem: invalid row/column: %d",
158  row < 0 ? row : column);
159  return;
160  }
161  if (columnSpan < 1 || rowSpan < 1) {
162  qWarning("QGraphicsGridLayout::addItem: invalid row span/column span: %d",
163  rowSpan < 1 ? rowSpan : columnSpan);
164  return;
165  }
166  if (!item) {
167  qWarning("QGraphicsGridLayout::addItem: cannot add null item");
168  return;
169  }
170  if (item == this) {
171  qWarning("QGraphicsGridLayout::addItem: cannot insert itself");
172  return;
173  }
174 
175  d->addChildLayoutItem(item);
176 
177  new QGridLayoutItem(&d->engine, item, row, column, rowSpan, columnSpan, alignment);
178  invalidate();
179 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
Qt::Alignment alignment(QGraphicsLayoutItem *item) const
Returns the alignment for item.
void invalidate()
Reimplemented Function

◆ addItem() [2/2]

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

Adds item to the grid on row and column.

You can specify an optional alignment for item.

Definition at line 134 of file qgraphicsgridlayout.h.

135 { addItem(aitem, arow, acolumn, 1, 1, aalignment); }
void addItem(QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment=0)
Adds item to the grid on row and column.

◆ alignment()

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

Returns the alignment for item.

Definition at line 502 of file qgraphicsgridlayout.cpp.

503 {
504  Q_D(const QGraphicsGridLayout);
505  return d->engine.alignment(item);
506 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnAlignment()

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

Returns the alignment for column.

Definition at line 483 of file qgraphicsgridlayout.cpp.

484 {
485  Q_D(const QGraphicsGridLayout);
486  return d->engine.rowAlignment(column, Qt::Horizontal);
487 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnCount()

int QGraphicsGridLayout::columnCount ( ) const

Returns the number of columns in the grid layout.

This is always one more than the index of the last column that is occupied by a layout item (empty columns are counted except for those at the end).

Definition at line 524 of file qgraphicsgridlayout.cpp.

Referenced by itemAt().

525 {
526  Q_D(const QGraphicsGridLayout);
527  return d->engine.effectiveLastRow(Qt::Horizontal) + 1;
528 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnMaximumWidth()

qreal QGraphicsGridLayout::columnMaximumWidth ( int  column) const

Returns the maximum width for column.

Definition at line 434 of file qgraphicsgridlayout.cpp.

435 {
436  Q_D(const QGraphicsGridLayout);
437  return d->engine.rowSizeHint(Qt::MaximumSize, column, Qt::Horizontal);
438 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnMinimumWidth()

qreal QGraphicsGridLayout::columnMinimumWidth ( int  column) const

Returns the minimum width for column.

Definition at line 396 of file qgraphicsgridlayout.cpp.

397 {
398  Q_D(const QGraphicsGridLayout);
399  return d->engine.rowSizeHint(Qt::MinimumSize, column, Qt::Horizontal);
400 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnPreferredWidth()

qreal QGraphicsGridLayout::columnPreferredWidth ( int  column) const

Returns the preferred width for column.

Definition at line 415 of file qgraphicsgridlayout.cpp.

416 {
417  Q_D(const QGraphicsGridLayout);
418  return d->engine.rowSizeHint(Qt::PreferredSize, column, Qt::Horizontal);
419 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnSpacing()

qreal QGraphicsGridLayout::columnSpacing ( int  column) const

Returns the column spacing for column.

Definition at line 271 of file qgraphicsgridlayout.cpp.

272 {
273  Q_D(const QGraphicsGridLayout);
274  return d->engine.rowSpacing(column, Qt::Horizontal);
275 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ columnStretchFactor()

int QGraphicsGridLayout::columnStretchFactor ( int  column) const

Returns the stretch factor for column.

Definition at line 309 of file qgraphicsgridlayout.cpp.

310 {
311  Q_D(const QGraphicsGridLayout);
312  return d->engine.rowStretchFactor(column, Qt::Horizontal);
313 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ count()

int QGraphicsGridLayout::count ( ) const
virtual

Returns the number of layout items in this grid layout.

Implements QGraphicsLayout.

Definition at line 548 of file qgraphicsgridlayout.cpp.

Referenced by ~QGraphicsGridLayout().

549 {
550  Q_D(const QGraphicsGridLayout);
551  return d->engine.itemCount();
552 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ horizontalSpacing()

qreal QGraphicsGridLayout::horizontalSpacing ( ) const

Returns the default horizontal spacing for the grid layout.

Definition at line 201 of file qgraphicsgridlayout.cpp.

202 {
203  Q_D(const QGraphicsGridLayout);
204  return d->engine.spacing(d->styleInfo(), Qt::Horizontal);
205 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ invalidate()

void QGraphicsGridLayout::invalidate ( )
virtual

Reimplemented Function

Reimplemented from QGraphicsLayout.

Definition at line 625 of file qgraphicsgridlayout.cpp.

Referenced by addItem(), removeAt(), setAlignment(), setColumnAlignment(), setColumnFixedWidth(), setColumnMaximumWidth(), setColumnMinimumWidth(), setColumnPreferredWidth(), setColumnSpacing(), setColumnStretchFactor(), setHorizontalSpacing(), setRowAlignment(), setRowFixedHeight(), setRowMaximumHeight(), setRowMinimumHeight(), setRowPreferredHeight(), setRowSpacing(), setRowStretchFactor(), setSpacing(), and setVerticalSpacing().

626 {
628  d->engine.invalidate();
630 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
virtual void invalidate()
Clears any cached geometry and size hint information in the layout, and posts a LayoutRequest event t...

◆ itemAt() [1/2]

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

Returns a pointer to the layout item at (row, column).

Definition at line 533 of file qgraphicsgridlayout.cpp.

Referenced by ~QGraphicsGridLayout().

534 {
535  Q_D(const QGraphicsGridLayout);
536  if (row < 0 || row >= rowCount() || column < 0 || column >= columnCount()) {
537  qWarning("QGraphicsGridLayout::itemAt: invalid row, column %d, %d", row, column);
538  return 0;
539  }
540  if (QGridLayoutItem *item = d->engine.itemAt(row, column))
541  return item->layoutItem();
542  return 0;
543 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
int columnCount() const
Returns the number of columns in the grid layout.
int rowCount() const
Returns the number of rows in the grid layout.

◆ itemAt() [2/2]

QGraphicsLayoutItem * QGraphicsGridLayout::itemAt ( int  index) const
virtual

Returns the layout item at index, or 0 if there is no layout item at this index.

Implements QGraphicsLayout.

Definition at line 558 of file qgraphicsgridlayout.cpp.

559 {
560  Q_D(const QGraphicsGridLayout);
561  if (index < 0 || index >= d->engine.itemCount()) {
562  qWarning("QGraphicsGridLayout::itemAt: invalid index %d", index);
563  return 0;
564  }
565  QGraphicsLayoutItem *item = 0;
566  if (QGridLayoutItem *gridItem = d->engine.itemAt(index))
567  item = gridItem->layoutItem();
568  return item;
569 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
quint16 index

◆ removeAt()

void QGraphicsGridLayout::removeAt ( int  index)
virtual

Removes the layout item at index without destroying it.

Ownership of the item is transferred to the caller.

See also
addItem()

Implements QGraphicsLayout.

Definition at line 577 of file qgraphicsgridlayout.cpp.

Referenced by removeItem(), and ~QGraphicsGridLayout().

578 {
580  if (index < 0 || index >= d->engine.itemCount()) {
581  qWarning("QGraphicsGridLayout::removeAt: invalid index %d", index);
582  return;
583  }
584  if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
585  if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
586  layoutItem->setParentLayoutItem(0);
587  d->engine.removeItem(gridItem);
588 
589  // recalculate rowInfo.count if we remove an item that is on the right/bottommost row
590  for (int j = 0; j < NOrientations; ++j) {
591  // 0: Hor, 1: Ver
592  const Qt::Orientation orient = (j == 0 ? Qt::Horizontal : Qt::Vertical);
593  const int oldCount = d->engine.rowCount(orient);
594  if (gridItem->lastRow(orient) == oldCount - 1) {
595  const int newCount = d->engine.effectiveLastRow(orient) + 1;
596  d->engine.removeRows(newCount, oldCount - newCount, orient);
597  }
598  }
599 
600  delete gridItem;
601  invalidate();
602  }
603 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qWarning(const char *,...)
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts...
void invalidate()
Reimplemented Function
quint16 index
Orientation
Definition: qnamespace.h:174

◆ removeItem()

void QGraphicsGridLayout::removeItem ( QGraphicsLayoutItem item)

Removes the layout item item without destroying it.

Since
4.8

Ownership of the item is transferred to the caller.

See also
addItem()

Definition at line 616 of file qgraphicsgridlayout.cpp.

617 {
619  int index = d->engine.indexOf(item);
620  removeAt(index);
621 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void removeAt(int index)
Removes the layout item at index without destroying it.
quint16 index

◆ rowAlignment()

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

Returns the alignment of row.

Definition at line 464 of file qgraphicsgridlayout.cpp.

465 {
466  Q_D(const QGraphicsGridLayout);
467  return d->engine.rowAlignment(row, Qt::Vertical);
468 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rowCount()

int QGraphicsGridLayout::rowCount ( ) const

Returns the number of rows in the grid layout.

This is always one more than the index of the last row that is occupied by a layout item (empty rows are counted except for those at the end).

Definition at line 513 of file qgraphicsgridlayout.cpp.

Referenced by itemAt().

514 {
515  Q_D(const QGraphicsGridLayout);
516  return d->engine.effectiveLastRow(Qt::Vertical) + 1;
517 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rowMaximumHeight()

qreal QGraphicsGridLayout::rowMaximumHeight ( int  row) const

Returns the maximum height for row, row.

Definition at line 366 of file qgraphicsgridlayout.cpp.

367 {
368  Q_D(const QGraphicsGridLayout);
369  return d->engine.rowSizeHint(Qt::MaximumSize, row, Qt::Vertical);
370 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rowMinimumHeight()

qreal QGraphicsGridLayout::rowMinimumHeight ( int  row) const

Returns the minimum height for row, row.

Definition at line 328 of file qgraphicsgridlayout.cpp.

329 {
330  Q_D(const QGraphicsGridLayout);
331  return d->engine.rowSizeHint(Qt::MinimumSize, row, Qt::Vertical);
332 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rowPreferredHeight()

qreal QGraphicsGridLayout::rowPreferredHeight ( int  row) const

Returns the preferred height for row, row.

Definition at line 347 of file qgraphicsgridlayout.cpp.

348 {
349  Q_D(const QGraphicsGridLayout);
350  return d->engine.rowSizeHint(Qt::PreferredSize, row, Qt::Vertical);
351 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rowSpacing()

qreal QGraphicsGridLayout::rowSpacing ( int  row) const

Returns the row spacing for row.

Definition at line 252 of file qgraphicsgridlayout.cpp.

253 {
254  Q_D(const QGraphicsGridLayout);
255  return d->engine.rowSpacing(row, Qt::Vertical);
256 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ rowStretchFactor()

int QGraphicsGridLayout::rowStretchFactor ( int  row) const

Returns the stretch factor for row.

Definition at line 290 of file qgraphicsgridlayout.cpp.

291 {
292  Q_D(const QGraphicsGridLayout);
293  return d->engine.rowStretchFactor(row, Qt::Vertical);
294 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

◆ setAlignment()

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

Sets the alignment for item to alignment.

Definition at line 492 of file qgraphicsgridlayout.cpp.

493 {
495  d->engine.setAlignment(item, alignment);
496  invalidate();
497 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Alignment alignment(QGraphicsLayoutItem *item) const
Returns the alignment for item.
void invalidate()
Reimplemented Function

◆ setColumnAlignment()

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

Sets the alignment for column to alignment.

Definition at line 473 of file qgraphicsgridlayout.cpp.

474 {
476  d->engine.setRowAlignment(column, alignment, Qt::Horizontal);
477  invalidate();
478 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Alignment alignment(QGraphicsLayoutItem *item) const
Returns the alignment for item.
void invalidate()
Reimplemented Function

◆ setColumnFixedWidth()

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

Sets the fixed width of column to width.

Definition at line 443 of file qgraphicsgridlayout.cpp.

444 {
446  d->engine.setRowSizeHint(Qt::MinimumSize, column, width, Qt::Horizontal);
447  d->engine.setRowSizeHint(Qt::MaximumSize, column, width, Qt::Horizontal);
448  invalidate();
449 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setColumnMaximumWidth()

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

Sets the maximum width of column to width.

Definition at line 424 of file qgraphicsgridlayout.cpp.

425 {
427  d->engine.setRowSizeHint(Qt::MaximumSize, column, width, Qt::Horizontal);
428  invalidate();
429 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setColumnMinimumWidth()

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

Sets the minimum width for column to width.

Definition at line 386 of file qgraphicsgridlayout.cpp.

387 {
389  d->engine.setRowSizeHint(Qt::MinimumSize, column, width, Qt::Horizontal);
390  invalidate();
391 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setColumnPreferredWidth()

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

Sets the preferred width for column to width.

Definition at line 405 of file qgraphicsgridlayout.cpp.

406 {
408  d->engine.setRowSizeHint(Qt::PreferredSize, column, width, Qt::Horizontal);
409  invalidate();
410 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setColumnSpacing()

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

Sets the spacing for column to spacing.

Definition at line 261 of file qgraphicsgridlayout.cpp.

262 {
264  d->engine.setRowSpacing(column, spacing, Qt::Horizontal);
265  invalidate();
266 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setColumnStretchFactor()

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

Sets the stretch factor for column to stretch.

Definition at line 299 of file qgraphicsgridlayout.cpp.

300 {
302  d->engine.setRowStretchFactor(column, stretch, Qt::Horizontal);
303  invalidate();
304 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setGeometry()

void QGraphicsGridLayout::setGeometry ( const QRectF rect)
virtual

Sets the bounding geometry of the grid layout to rect.

Reimplemented from QGraphicsLayoutItem.

Definition at line 644 of file qgraphicsgridlayout.cpp.

645 {
648  QRectF effectiveRect = geometry();
649  qreal left, top, right, bottom;
650  getContentsMargins(&left, &top, &right, &bottom);
651  Qt::LayoutDirection visualDir = d->visualDirection();
652  d->engine.setVisualDirection(visualDir);
653  if (visualDir == Qt::RightToLeft)
654  qSwap(left, right);
655  effectiveRect.adjust(+left, +top, -right, -bottom);
656  d->engine.setGeometries(d->styleInfo(), effectiveRect);
657 #ifdef QT_DEBUG
658  if (qt_graphicsLayoutDebug()) {
659  static int counter = 0;
660  qDebug("==== BEGIN DUMP OF QGraphicsGridLayout (%d)====", counter++);
661  d->dump(1);
662  qDebug("==== END DUMP OF QGraphicsGridLayout ====");
663  }
664 #endif
665 }
double d
Definition: qnumeric_p.h:62
virtual void setGeometry(const QRectF &rect)
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordi...
double qreal
Definition: qglobal.h:1193
void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
Reimplemented Function
bool qt_graphicsLayoutDebug()
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
QRectF geometry() const
Returns the item&#39;s geometry (e.
The QRectF class defines a rectangle in the plane using floating point precision. ...
Definition: qrect.h:511
LayoutDirection
Definition: qnamespace.h:1580
void qSwap(T &value1, T &value2)
Definition: qglobal.h:2181
void adjust(qreal x1, qreal y1, qreal x2, qreal y2)
Adds dx1, dy1, dx2 and dy2 respectively to the existing coordinates of the rectangle.
Definition: qrect.h:778
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ setHorizontalSpacing()

void QGraphicsGridLayout::setHorizontalSpacing ( qreal  spacing)

Sets the default horizontal spacing for the grid layout to spacing.

Definition at line 191 of file qgraphicsgridlayout.cpp.

192 {
194  d->engine.setSpacing(spacing, Qt::Horizontal);
195  invalidate();
196 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setRowAlignment()

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

Sets the alignment of row to alignment.

Definition at line 454 of file qgraphicsgridlayout.cpp.

455 {
457  d->engine.setRowAlignment(row, alignment, Qt::Vertical);
458  invalidate();
459 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
Qt::Alignment alignment(QGraphicsLayoutItem *item) const
Returns the alignment for item.
void invalidate()
Reimplemented Function

◆ setRowFixedHeight()

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

Sets the fixed height for row, row, to height.

Definition at line 375 of file qgraphicsgridlayout.cpp.

376 {
378  d->engine.setRowSizeHint(Qt::MinimumSize, row, height, Qt::Vertical);
379  d->engine.setRowSizeHint(Qt::MaximumSize, row, height, Qt::Vertical);
380  invalidate();
381 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setRowMaximumHeight()

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

Sets the maximum height for row, row, to height.

Definition at line 356 of file qgraphicsgridlayout.cpp.

357 {
359  d->engine.setRowSizeHint(Qt::MaximumSize, row, height, Qt::Vertical);
360  invalidate();
361 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setRowMinimumHeight()

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

Sets the minimum height for row, row, to height.

Definition at line 318 of file qgraphicsgridlayout.cpp.

319 {
321  d->engine.setRowSizeHint(Qt::MinimumSize, row, height, Qt::Vertical);
322  invalidate();
323 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setRowPreferredHeight()

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

Sets the preferred height for row, row, to height.

Definition at line 337 of file qgraphicsgridlayout.cpp.

338 {
340  d->engine.setRowSizeHint(Qt::PreferredSize, row, height, Qt::Vertical);
341  invalidate();
342 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setRowSpacing()

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

Sets the spacing for row to spacing.

Definition at line 242 of file qgraphicsgridlayout.cpp.

243 {
245  d->engine.setRowSpacing(row, spacing, Qt::Vertical);
246  invalidate();
247 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setRowStretchFactor()

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

Sets the stretch factor for row to stretch.

Definition at line 280 of file qgraphicsgridlayout.cpp.

281 {
283  d->engine.setRowStretchFactor(row, stretch, Qt::Vertical);
284  invalidate();
285 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setSpacing()

void QGraphicsGridLayout::setSpacing ( qreal  spacing)

Sets the grid layout's default spacing, both vertical and horizontal, to spacing.

See also
rowSpacing(), columnSpacing()

Definition at line 232 of file qgraphicsgridlayout.cpp.

233 {
235  d->engine.setSpacing(spacing, Qt::Horizontal | Qt::Vertical);
236  invalidate();
237 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ setVerticalSpacing()

void QGraphicsGridLayout::setVerticalSpacing ( qreal  spacing)

Sets the default vertical spacing for the grid layout to spacing.

Definition at line 210 of file qgraphicsgridlayout.cpp.

211 {
213  d->engine.setSpacing(spacing, Qt::Vertical);
214  invalidate();
215 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
void invalidate()
Reimplemented Function

◆ sizeHint()

QSizeF QGraphicsGridLayout::sizeHint ( Qt::SizeHint  which,
const QSizeF constraint = QSizeF() 
) const
virtual

Reimplemented Function

Implements QGraphicsLayoutItem.

Definition at line 670 of file qgraphicsgridlayout.cpp.

671 {
672  Q_D(const QGraphicsGridLayout);
673  qreal left, top, right, bottom;
674  getContentsMargins(&left, &top, &right, &bottom);
675  const QSizeF extraMargins(left + right, top + bottom);
676  return d->engine.sizeHint(d->styleInfo(), which , constraint - extraMargins) + extraMargins;
677 }
double d
Definition: qnumeric_p.h:62
double qreal
Definition: qglobal.h:1193
void getContentsMargins(qreal *left, qreal *top, qreal *right, qreal *bottom) const
Reimplemented Function
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482
The QSizeF class defines the size of a two-dimensional object using floating point precision...
Definition: qsize.h:202
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ verticalSpacing()

qreal QGraphicsGridLayout::verticalSpacing ( ) const

Returns the default vertical spacing for the grid layout.

Definition at line 220 of file qgraphicsgridlayout.cpp.

221 {
222  Q_D(const QGraphicsGridLayout);
223  return d->engine.spacing(d->styleInfo(), Qt::Vertical);
224 }
double d
Definition: qnumeric_p.h:62
The QGraphicsGridLayout class provides a grid layout for managing widgets in Graphics View...
#define Q_D(Class)
Definition: qglobal.h:2482

The documentation for this class was generated from the following files: