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

The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View. More...

#include <qgraphicslinearlayout.h>

Inheritance diagram for QGraphicsLinearLayout:
QGraphicsLayout QGraphicsLayoutItem

Public Functions

void addItem (QGraphicsLayoutItem *item)
 This convenience function is equivalent to calling insertItem(-1, item). More...
 
void addStretch (int stretch=1)
 This convenience function is equivalent to calling insertStretch(-1, stretch). More...
 
Qt::Alignment alignment (QGraphicsLayoutItem *item) const
 Returns the alignment for item. More...
 
int count () const
 Reimplemented Function More...
 
void dump (int indent=0) const
 
void insertItem (int index, QGraphicsLayoutItem *item)
 Inserts item into the layout at index, or before any item that is currently at index. More...
 
void insertStretch (int index, int stretch=1)
 Inserts a stretch of stretch at index, or before any item that is currently at index. More...
 
void invalidate ()
 Reimplemented Function More...
 
QGraphicsLayoutItemitemAt (int index) const
 When iterating from 0 and up, it will return the items in the visual arranged order. More...
 
qreal itemSpacing (int index) const
 Returns the spacing after item at index. More...
 
Qt::Orientation orientation () const
 Returns the layout orientation. More...
 
 QGraphicsLinearLayout (QGraphicsLayoutItem *parent=0)
 Constructs a QGraphicsLinearLayout instance using Qt::Horizontal orientation. More...
 
 QGraphicsLinearLayout (Qt::Orientation orientation, QGraphicsLayoutItem *parent=0)
 Constructs a QGraphicsLinearLayout instance. More...
 
void removeAt (int index)
 Removes the item at index without destroying it. More...
 
void removeItem (QGraphicsLayoutItem *item)
 Removes item from the layout without destroying it. More...
 
void setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment)
 Sets the alignment of item to alignment. More...
 
void setGeometry (const QRectF &rect)
 Reimplemented Function More...
 
void setItemSpacing (int index, qreal spacing)
 Sets the spacing after item at index to spacing. More...
 
void setOrientation (Qt::Orientation orientation)
 Change the layout orientation to orientation. More...
 
void setSpacing (qreal spacing)
 Sets the layout's spacing to spacing. More...
 
void setStretchFactor (QGraphicsLayoutItem *item, int stretch)
 Sets the stretch factor for item to stretch. More...
 
QSizeF sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const
 Reimplemented Function More...
 
qreal spacing () const
 Returns the layout's spacing. More...
 
int stretchFactor (QGraphicsLayoutItem *item) const
 Returns the stretch factor for item. More...
 
virtual ~QGraphicsLinearLayout ()
 Destroys the QGraphicsLinearLayout 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 QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.

Since
4.4

The default orientation for a linear layout is Qt::Horizontal. You can choose a vertical orientation either by calling setOrientation(), or by passing Qt::Vertical to QGraphicsLinearLayout's constructor.

The most common way to use QGraphicsLinearLayout 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().

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

You can add widgets, layouts, stretches (addStretch(), insertStretch() or setStretchFactor()), and spacings (setItemSpacing()) to a linear layout. 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() or removeItem() will remove an item from the layout, without destroying it.

Size Hints and Size Policies in QGraphicsLinearLayout

QGraphicsLinearLayout respects each item's size hints and size policies, and when the layout contains 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(). By default, items are aligned to the top left.

Spacing within QGraphicsLinearLayout

Between the items, the layout distributes some space. The actual amount of space depends on the managed widget's current style, but the common spacing is 4. You can also set your own spacing by calling setSpacing(), and get the current spacing value by calling spacing(). If you want to configure individual spacing for your items, you can call setItemSpacing().

Stretch Factor in QGraphicsLinearLayout

You can assign a stretch factor to each item to control how much space it will get compared to the other items. By default, two identical widgets arranged in a linear layout will have the same size, but if the first widget has a stretch factor of 1 and the second widget has a stretch factor of 2, the first widget will get 1/3 of the available space, and the second will get 2/3.

QGraphicsLinearLayout calculates the distribution of sizes by adding up the stretch factors of all items, and then dividing the available space accordingly. The default stretch factor is 0 for all items; a factor of 0 means the item does not have any defined stretch factor; effectively this is the same as setting the stretch factor to 1. The stretch factor only applies to the available space in the lengthwise direction of the layout (following its orientation). If you want to control both the item's horizontal and vertical stretch, you can use QGraphicsGridLayout instead.

QGraphicsLinearLayout Compared to Other Layouts

QGraphicsLinearLayout is very similar to QVBoxLayout and QHBoxLayout, but in contrast to these classes, it is used to manage QGraphicsWidget and QGraphicsLayout instead of QWidget and QLayout.

See also
QGraphicsGridLayout, QGraphicsWidget

Definition at line 58 of file qgraphicslinearlayout.h.

Constructors and Destructors

◆ QGraphicsLinearLayout() [1/2]

QGraphicsLinearLayout::QGraphicsLinearLayout ( QGraphicsLayoutItem parent = 0)

Constructs a QGraphicsLinearLayout instance using Qt::Horizontal orientation.

parent is passed to QGraphicsLayout's constructor.

Definition at line 200 of file qgraphicslinearlayout.cpp.

202 {
203 }
QGraphicsLayout(QGraphicsLayoutItem *parent=0)
Contructs a QGraphicsLayout object.

◆ QGraphicsLinearLayout() [2/2]

QGraphicsLinearLayout::QGraphicsLinearLayout ( Qt::Orientation  orientation,
QGraphicsLayoutItem parent = 0 
)

Constructs a QGraphicsLinearLayout instance.

You can pass the orientation for the layout, either horizontal or vertical, and parent is passed to QGraphicsLayout's constructor.

Definition at line 191 of file qgraphicslinearlayout.cpp.

193 {
194 }
QGraphicsLayout(QGraphicsLayoutItem *parent=0)
Contructs a QGraphicsLayout object.
Qt::Orientation orientation() const
Returns the layout orientation.

◆ ~QGraphicsLinearLayout()

QGraphicsLinearLayout::~QGraphicsLinearLayout ( )
virtual

Destroys the QGraphicsLinearLayout object.

Definition at line 208 of file qgraphicslinearlayout.cpp.

209 {
210  for (int i = count() - 1; i >= 0; --i) {
211  QGraphicsLayoutItem *item = itemAt(i);
212  // The following lines can be removed, but this removes the item
213  // from the layout more efficiently than the implementation of
214  // ~QGraphicsLayoutItem.
215  removeAt(i);
216  if (item) {
217  item->setParentLayoutItem(0);
218  if (item->ownedByLayout())
219  delete item;
220  }
221  }
222 }
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.
QGraphicsLayoutItem * itemAt(int index) const
When iterating from 0 and up, it will return the items in the visual arranged order.
void removeAt(int index)
Removes the item at index without destroying it.
int count() const
Reimplemented Function

Functions

◆ addItem()

void QGraphicsLinearLayout::addItem ( QGraphicsLayoutItem item)
inline

This convenience function is equivalent to calling insertItem(-1, item).

Definition at line 68 of file qgraphicslinearlayout.h.

68 { insertItem(-1, item); }
void insertItem(int index, QGraphicsLayoutItem *item)
Inserts item into the layout at index, or before any item that is currently at index.

◆ addStretch()

void QGraphicsLinearLayout::addStretch ( int  stretch = 1)
inline

This convenience function is equivalent to calling insertStretch(-1, stretch).

Definition at line 69 of file qgraphicslinearlayout.h.

69 { insertStretch(-1, stretch); }
void insertStretch(int index, int stretch=1)
Inserts a stretch of stretch at index, or before any item that is currently at index.

◆ alignment()

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

Returns the alignment for item.

The default alignment is Qt::AlignTop | Qt::AlignLeft.

The alignment decides how the item is positioned within its assigned space in the case where there's more space available in the layout than the widgets can occupy.

See also
setAlignment()

Definition at line 459 of file qgraphicslinearlayout.cpp.

Referenced by setAlignment().

460 {
461  Q_D(const QGraphicsLinearLayout);
462  return d->engine.alignment(item);
463 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...

◆ count()

int QGraphicsLinearLayout::count ( ) const
virtual

Reimplemented Function

Implements QGraphicsLayout.

Definition at line 475 of file qgraphicslinearlayout.cpp.

Referenced by ~QGraphicsLinearLayout().

476 {
477  Q_D(const QGraphicsLinearLayout);
478  return d->engine.itemCount();
479 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...

◆ dump()

void QGraphicsLinearLayout::dump ( int  indent = 0) const
Warning
This function is not part of the public interface.

Definition at line 557 of file qgraphicslinearlayout.cpp.

Referenced by setGeometry().

558 {
559 #ifdef QT_DEBUG
560  if (qt_graphicsLayoutDebug()) {
561  Q_D(const QGraphicsLinearLayout);
562  qDebug("%*s%s layout", indent, "",
563  d->orientation == Qt::Horizontal ? "Horizontal" : "Vertical");
564  d->engine.dump(indent + 1);
565  }
566 #else
567  Q_UNUSED(indent);
568 #endif
569 }
double d
Definition: qnumeric_p.h:62
bool qt_graphicsLayoutDebug()
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT void qDebug(const char *,...)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729

◆ insertItem()

void QGraphicsLinearLayout::insertItem ( int  index,
QGraphicsLayoutItem item 
)

Inserts item into the layout at index, or before any item that is currently at index.

See also
addItem(), itemAt(), insertStretch(), setItemSpacing()

Definition at line 273 of file qgraphicslinearlayout.cpp.

274 {
276  if (!item) {
277  qWarning("QGraphicsLinearLayout::insertItem: cannot insert null item");
278  return;
279  }
280  if (item == this) {
281  qWarning("QGraphicsLinearLayout::insertItem: cannot insert itself");
282  return;
283  }
284  d->addChildLayoutItem(item);
285 
286  Q_ASSERT(item);
287  d->fixIndex(&index);
288  d->engine.insertRow(index, d->orientation);
289  new QGridLayoutItem(&d->engine, item, d->gridRow(index), d->gridColumn(index), 1, 1, 0, index);
290  invalidate();
291 }
double d
Definition: qnumeric_p.h:62
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
Q_CORE_EXPORT void qWarning(const char *,...)
void invalidate()
Reimplemented Function
quint16 index

◆ insertStretch()

void QGraphicsLinearLayout::insertStretch ( int  index,
int  stretch = 1 
)

Inserts a stretch of stretch at index, or before any item that is currently at index.

See also
addStretch(), setStretchFactor(), setItemSpacing(), insertItem()

Definition at line 299 of file qgraphicslinearlayout.cpp.

300 {
302  d->fixIndex(&index);
303  d->engine.insertRow(index, d->orientation);
304  d->engine.setRowStretchFactor(index, stretch, d->orientation);
305  invalidate();
306 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void invalidate()
Reimplemented Function
quint16 index

◆ invalidate()

void QGraphicsLinearLayout::invalidate ( )
virtual

Reimplemented Function

Reimplemented from QGraphicsLayout.

Definition at line 547 of file qgraphicslinearlayout.cpp.

Referenced by insertItem(), insertStretch(), removeAt(), removeItem(), setAlignment(), setItemSpacing(), setOrientation(), setSpacing(), and setStretchFactor().

548 {
550  d->engine.invalidate();
552 }
double d
Definition: qnumeric_p.h:62
#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...
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...

◆ itemAt()

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

When iterating from 0 and up, it will return the items in the visual arranged order.

Reimplemented Function

Implements QGraphicsLayout.

Definition at line 488 of file qgraphicslinearlayout.cpp.

Referenced by ~QGraphicsLinearLayout().

489 {
490  Q_D(const QGraphicsLinearLayout);
491  if (index < 0 || index >= d->engine.itemCount()) {
492  qWarning("QGraphicsLinearLayout::itemAt: invalid index %d", index);
493  return 0;
494  }
495  QGraphicsLayoutItem *item = 0;
496  if (QGridLayoutItem *gridItem = d->engine.itemAt(index))
497  item = gridItem->layoutItem();
498  return item;
499 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
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

◆ itemSpacing()

qreal QGraphicsLinearLayout::itemSpacing ( int  index) const

Returns the spacing after item at index.

Definition at line 388 of file qgraphicslinearlayout.cpp.

389 {
390  Q_D(const QGraphicsLinearLayout);
391  return d->engine.rowSpacing(index, d->orientation);
392 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
quint16 index

◆ orientation()

Qt::Orientation QGraphicsLinearLayout::orientation ( ) const

Returns the layout orientation.

See also
setOrientation()

Definition at line 244 of file qgraphicslinearlayout.cpp.

Referenced by setOrientation().

245 {
246  Q_D(const QGraphicsLinearLayout);
247  return d->orientation;
248 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...

◆ removeAt()

void QGraphicsLinearLayout::removeAt ( int  index)
virtual

Removes the item at index without destroying it.

Ownership of the item is transferred to the caller.

See also
removeItem(), insertItem()

Implements QGraphicsLayout.

Definition at line 331 of file qgraphicslinearlayout.cpp.

Referenced by ~QGraphicsLinearLayout().

332 {
334  if (index < 0 || index >= d->engine.itemCount()) {
335  qWarning("QGraphicsLinearLayout::removeAt: invalid index %d", index);
336  return;
337  }
338  if (QGridLayoutItem *gridItem = d->engine.itemAt(index)) {
339  if (QGraphicsLayoutItem *layoutItem = gridItem->layoutItem())
340  layoutItem->setParentLayoutItem(0);
341  d->removeGridItem(gridItem);
342  delete gridItem;
343  invalidate();
344  }
345 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
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

◆ removeItem()

void QGraphicsLinearLayout::removeItem ( QGraphicsLayoutItem item)

Removes item from the layout without destroying it.

Ownership of item is transferred to the caller.

See also
removeAt(), insertItem()

Definition at line 314 of file qgraphicslinearlayout.cpp.

315 {
317  if (QGridLayoutItem *gridItem = d->engine.findLayoutItem(item)) {
318  item->setParentLayoutItem(0);
319  d->removeGridItem(gridItem);
320  delete gridItem;
321  invalidate();
322  }
323 }
double d
Definition: qnumeric_p.h:62
void setParentLayoutItem(QGraphicsLayoutItem *parent)
Sets the parent of this QGraphicsLayoutItem to parent.
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void invalidate()
Reimplemented Function

◆ setAlignment()

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

Sets the alignment of item to alignment.

If item's alignment changes, the layout is automatically invalidated.

See also
alignment(), invalidate()

Definition at line 440 of file qgraphicslinearlayout.cpp.

441 {
443  if (this->alignment(item) == alignment)
444  return;
445  d->engine.setAlignment(item, alignment);
446  invalidate();
447 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void invalidate()
Reimplemented Function
Qt::Alignment alignment(QGraphicsLayoutItem *item) const
Returns the alignment for item.

◆ setGeometry()

void QGraphicsLinearLayout::setGeometry ( const QRectF rect)
virtual

Reimplemented Function

Reimplemented from QGraphicsLayoutItem.

Definition at line 504 of file qgraphicslinearlayout.cpp.

505 {
508  QRectF effectiveRect = geometry();
509  qreal left, top, right, bottom;
510  getContentsMargins(&left, &top, &right, &bottom);
511  Qt::LayoutDirection visualDir = d->visualDirection();
512  d->engine.setVisualDirection(visualDir);
513  if (visualDir == Qt::RightToLeft)
514  qSwap(left, right);
515  effectiveRect.adjust(+left, +top, -right, -bottom);
516 #ifdef QT_DEBUG
517  if (qt_graphicsLayoutDebug()) {
518  static int counter = 0;
519  qDebug() << counter++ << "QGraphicsLinearLayout::setGeometry - " << rect;
520  dump(1);
521  }
522 #endif
523  d->engine.setGeometries(d->styleInfo(), effectiveRect);
524 #ifdef QT_DEBUG
525  if (qt_graphicsLayoutDebug()) {
526  qDebug() << "post dump";
527  dump(1);
528  }
529 #endif
530 }
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()
#define Q_D(Class)
Definition: qglobal.h:2482
Q_CORE_EXPORT QTextStream & right(QTextStream &s)
Q_CORE_EXPORT void qDebug(const char *,...)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
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
void dump(int indent=0) const
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ setItemSpacing()

void QGraphicsLinearLayout::setItemSpacing ( int  index,
qreal  spacing 
)

Sets the spacing after item at index to spacing.

Definition at line 379 of file qgraphicslinearlayout.cpp.

380 {
382  d->engine.setRowSpacing(index, spacing, d->orientation);
383  invalidate();
384 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void invalidate()
Reimplemented Function
qreal spacing() const
Returns the layout&#39;s spacing.
quint16 index

◆ setOrientation()

void QGraphicsLinearLayout::setOrientation ( Qt::Orientation  orientation)

Change the layout orientation to orientation.

Changing the layout orientation will automatically invalidate the layout.

See also
orientation()

Definition at line 230 of file qgraphicslinearlayout.cpp.

231 {
233  if (orientation != d->orientation) {
234  d->engine.transpose();
235  d->orientation = orientation;
236  invalidate();
237  }
238 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
void invalidate()
Reimplemented Function
Qt::Orientation orientation() const
Returns the layout orientation.

◆ setSpacing()

void QGraphicsLinearLayout::setSpacing ( qreal  spacing)

Sets the layout's spacing to spacing.

Spacing refers to the vertical and horizontal distances between items.

See also
setItemSpacing(), setStretchFactor(), QGraphicsGridLayout::setSpacing()

Definition at line 353 of file qgraphicslinearlayout.cpp.

354 {
356  if (spacing < 0) {
357  qWarning("QGraphicsLinearLayout::setSpacing: invalid spacing %g", spacing);
358  return;
359  }
360  d->engine.setSpacing(spacing, Qt::Horizontal | Qt::Vertical);
361  invalidate();
362 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
Q_CORE_EXPORT void qWarning(const char *,...)
void invalidate()
Reimplemented Function
qreal spacing() const
Returns the layout&#39;s spacing.

◆ setStretchFactor()

void QGraphicsLinearLayout::setStretchFactor ( QGraphicsLayoutItem item,
int  stretch 
)

Sets the stretch factor for item to stretch.

If an item's stretch factor changes, this function will invalidate the layout.

Setting stretch to 0 removes the stretch factor from the item, and is effectively equivalent to setting stretch to 1.

See also
stretchFactor()

Definition at line 403 of file qgraphicslinearlayout.cpp.

404 {
406  if (!item) {
407  qWarning("QGraphicsLinearLayout::setStretchFactor: cannot assign"
408  " a stretch factor to a null item");
409  return;
410  }
411  if (stretchFactor(item) == stretch)
412  return;
413  d->engine.setStretchFactor(item, stretch, d->orientation);
414  invalidate();
415 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
Q_CORE_EXPORT void qWarning(const char *,...)
void invalidate()
Reimplemented Function
int stretchFactor(QGraphicsLayoutItem *item) const
Returns the stretch factor for item.

◆ sizeHint()

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

Reimplemented Function

Implements QGraphicsLayoutItem.

Definition at line 535 of file qgraphicslinearlayout.cpp.

536 {
537  Q_D(const QGraphicsLinearLayout);
538  qreal left, top, right, bottom;
539  getContentsMargins(&left, &top, &right, &bottom);
540  const QSizeF extraMargins(left + right, top + bottom);
541  return d->engine.sizeHint(d->styleInfo(), which , constraint - extraMargins) + extraMargins;
542 }
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
#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)
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
Q_CORE_EXPORT QTextStream & left(QTextStream &s)

◆ spacing()

qreal QGraphicsLinearLayout::spacing ( ) const

Returns the layout's spacing.

Spacing refers to the vertical and horizontal distances between items.

See also
setSpacing()

Definition at line 370 of file qgraphicslinearlayout.cpp.

371 {
372  Q_D(const QGraphicsLinearLayout);
373  return d->engine.spacing(d->styleInfo(), d->orientation);
374 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...

◆ stretchFactor()

int QGraphicsLinearLayout::stretchFactor ( QGraphicsLayoutItem item) const

Returns the stretch factor for item.

The default stretch factor is 0, meaning that the item has no assigned stretch factor.

See also
setStretchFactor()

Definition at line 423 of file qgraphicslinearlayout.cpp.

Referenced by setStretchFactor().

424 {
425  Q_D(const QGraphicsLinearLayout);
426  if (!item) {
427  qWarning("QGraphicsLinearLayout::setStretchFactor: cannot return"
428  " a stretch factor for a null item");
429  return 0;
430  }
431  return d->engine.stretchFactor(item, d->orientation);
432 }
double d
Definition: qnumeric_p.h:62
#define Q_D(Class)
Definition: qglobal.h:2482
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Grap...
Q_CORE_EXPORT void qWarning(const char *,...)

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