Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QGraphicsLinearLayout Class

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

Header:#include <QGraphicsLinearLayout>
Since: Qt 4.4
Inherits:QGraphicsLayout

Public Functions

QGraphicsLinearLayout(QGraphicsLayoutItem * parent = 0)
QGraphicsLinearLayout(Qt::Orientation orientation, QGraphicsLayoutItem * parent = 0)
virtual~QGraphicsLinearLayout()
voidaddItem(QGraphicsLayoutItem * item)
voidaddStretch(int stretch = 1)
Qt::Alignmentalignment(QGraphicsLayoutItem * item) const
voidinsertItem(int index, QGraphicsLayoutItem * item)
voidinsertStretch(int index, int stretch = 1)
qrealitemSpacing(int index) const
Qt::Orientationorientation() const
voidremoveItem(QGraphicsLayoutItem * item)
voidsetAlignment(QGraphicsLayoutItem * item, Qt::Alignment alignment)
voidsetItemSpacing(int index, qreal spacing)
voidsetOrientation(Qt::Orientation orientation)
voidsetSpacing(qreal spacing)
voidsetStretchFactor(QGraphicsLayoutItem * item, int stretch)
qrealspacing() const
intstretchFactor(QGraphicsLayoutItem * item) const

Reimplemented Public Functions

virtual intcount() const
virtual voidinvalidate()
virtual QGraphicsLayoutItem *itemAt(int index) const
virtual voidremoveAt(int index)
virtual voidsetGeometry(const QRectF & rect)
virtual QSizeFsizeHint(Qt::SizeHint which, const QSizeF & constraint = QSizeF()) const

Additional Inherited Members

Detailed Description

TheQGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.

The default orientation for a linear layout isQt::Horizontal. You can choose a vertical orientation either by callingsetOrientation(), or by passingQt::Vertical toQGraphicsLinearLayout's constructor.

The most common way to useQGraphicsLinearLayout is to construct an object on the heap with no parent, add widgets and layouts by callingaddItem(), and finally assign the layout to a widget by callingQGraphicsWidget::setLayout().

QGraphicsScene scene;QGraphicsWidget*textEdit= scene.addWidget(newQTextEdit);QGraphicsWidget*pushButton= scene.addWidget(newQPushButton);QGraphicsLinearLayout*layout=newQGraphicsLinearLayout;layout->addItem(textEdit);layout->addItem(pushButton);QGraphicsWidget*form=newQGraphicsWidget;form->setLayout(layout);scene.addItem(form);

You can add widgets, layouts, stretches (addStretch(),insertStretch() orsetStretchFactor()), and spacings (setItemSpacing()) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits fromQGraphicsItem (such asQGraphicsWidget) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation ofQGraphicsLayoutItem::setOwnedByLayout() how to handle this. You can access each item in the layout by callingcount() anditemAt(). CallingremoveAt() orremoveItem() 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 callingsetAlignment(), and check the alignment for any item by callingalignment(). 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 callingsetSpacing(), and get the current spacing value by callingspacing(). If you want to configure individual spacing for your items, you can callsetItemSpacing().

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 useQGraphicsGridLayout instead.

QGraphicsLinearLayout Compared to Other Layouts

QGraphicsLinearLayout is very similar toQVBoxLayout andQHBoxLayout, but in contrast to these classes, it is used to manageQGraphicsWidget andQGraphicsLayout instead ofQWidget andQLayout.

See alsoQGraphicsGridLayout andQGraphicsWidget.

Member Function Documentation

QGraphicsLinearLayout::QGraphicsLinearLayout(QGraphicsLayoutItem * parent = 0)

Constructs aQGraphicsLinearLayout instance usingQt::Horizontal orientation.parent is passed toQGraphicsLayout's constructor.

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

Constructs aQGraphicsLinearLayout instance. You can pass theorientation for the layout, either horizontal or vertical, andparent is passed toQGraphicsLayout's constructor.

[virtual]QGraphicsLinearLayout::~QGraphicsLinearLayout()

Destroys theQGraphicsLinearLayout object.

void QGraphicsLinearLayout::addItem(QGraphicsLayoutItem * item)

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

void QGraphicsLinearLayout::addStretch(int stretch = 1)

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

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

Returns the alignment foritem. The default alignment isQt::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 alsosetAlignment().

[virtual]int QGraphicsLinearLayout::count() const

Reimplemented fromQGraphicsLayout::count().

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

Insertsitem into the layout atindex, or before any item that is currently atindex.

See alsoaddItem(),itemAt(),insertStretch(), andsetItemSpacing().

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

Inserts a stretch ofstretch atindex, or before any item that is currently atindex.

See alsoaddStretch(),setStretchFactor(),setItemSpacing(), andinsertItem().

[virtual]void QGraphicsLinearLayout::invalidate()

Reimplemented fromQGraphicsLayout::invalidate().

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

Reimplemented fromQGraphicsLayout::itemAt().

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

qreal QGraphicsLinearLayout::itemSpacing(int index) const

Returns the spacing after item atindex.

See alsosetItemSpacing().

Qt::Orientation QGraphicsLinearLayout::orientation() const

Returns the layout orientation.

See alsosetOrientation().

[virtual]void QGraphicsLinearLayout::removeAt(int index)

Reimplemented fromQGraphicsLayout::removeAt().

Removes the item atindex without destroying it. Ownership of the item is transferred to the caller.

See alsoremoveItem() andinsertItem().

void QGraphicsLinearLayout::removeItem(QGraphicsLayoutItem * item)

Removesitem from the layout without destroying it. Ownership ofitem is transferred to the caller.

See alsoremoveAt() andinsertItem().

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

Sets the alignment ofitem toalignment. Ifitem's alignment changes, the layout is automatically invalidated.

See alsoalignment() andinvalidate().

[virtual]void QGraphicsLinearLayout::setGeometry(constQRectF & rect)

Reimplemented fromQGraphicsLayoutItem::setGeometry().

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

Sets the spacing after item atindex tospacing.

See alsoitemSpacing().

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

Change the layout orientation toorientation. Changing the layout orientation will automatically invalidate the layout.

See alsoorientation().

void QGraphicsLinearLayout::setSpacing(qreal spacing)

Sets the layout's spacing tospacing. Spacing refers to the vertical and horizontal distances between items.

See alsospacing(),setItemSpacing(),setStretchFactor(), andQGraphicsGridLayout::setSpacing().

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

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

Settingstretch to 0 removes the stretch factor from the item, and is effectively equivalent to settingstretch to 1.

See alsostretchFactor().

[virtual]QSizeF QGraphicsLinearLayout::sizeHint(Qt::SizeHint which, constQSizeF & constraint = QSizeF()) const

Reimplemented fromQGraphicsLayoutItem::sizeHint().

qreal QGraphicsLinearLayout::spacing() const

Returns the layout's spacing. Spacing refers to the vertical and horizontal distances between items.

See alsosetSpacing().

int QGraphicsLinearLayout::stretchFactor(QGraphicsLayoutItem * item) const

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

See alsosetStretchFactor().

© 2016 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 theGNU 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.


[8]ページ先頭

©2009-2025 Movatter.jp