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

QBoxLayout Class

TheQBoxLayout class lines up child widgets horizontally or vertically.More...

Header:#include <QBoxLayout>
Inherits:QLayout
Inherited By:

Q3HBoxLayout,Q3VBoxLayout,QHBoxLayout, andQVBoxLayout

Public Types

enumDirection { LeftToRight, RightToLeft, TopToBottom, BottomToTop }

Public Functions

QBoxLayout(Direction dir, QWidget * parent = 0)
~QBoxLayout()
voidaddLayout(QLayout * layout, int stretch = 0)
voidaddSpacerItem(QSpacerItem * spacerItem)
voidaddSpacing(int size)
voidaddStretch(int stretch = 0)
voidaddStrut(int size)
voidaddWidget(QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0)
Directiondirection() const
voidinsertLayout(int index, QLayout * layout, int stretch = 0)
voidinsertSpacerItem(int index, QSpacerItem * spacerItem)
voidinsertSpacing(int index, int size)
voidinsertStretch(int index, int stretch = 0)
voidinsertWidget(int index, QWidget * widget, int stretch = 0, Qt::Alignment alignment = 0)
voidsetDirection(Direction direction)
voidsetSpacing(int spacing)
voidsetStretch(int index, int stretch)
boolsetStretchFactor(QWidget * widget, int stretch)
boolsetStretchFactor(QLayout * layout, int stretch)
intspacing() const
intstretch(int index) const

Reimplemented Public Functions

virtual voidaddItem(QLayoutItem * item)
virtual intcount() const
virtual Qt::OrientationsexpandingDirections() const
virtual boolhasHeightForWidth() const
virtual intheightForWidth(int w) const
virtual voidinvalidate()
virtual QLayoutItem *itemAt(int index) const
virtual QSizemaximumSize() const
virtual intminimumHeightForWidth(int w) const
virtual QSizeminimumSize() const
virtual voidsetGeometry(const QRect & r)
virtual QSizesizeHint() const
virtual QLayoutItem *takeAt(int index)
  • 35 public functions inherited fromQLayout
  • 29 public functions inherited fromQObject
  • 17 public functions inherited fromQLayoutItem

Protected Functions

voidinsertItem(int index, QLayoutItem * item)
  • 4 protected functions inherited fromQLayout
  • 8 protected functions inherited fromQObject

Additional Inherited Members

  • 2 properties inherited fromQLayout
  • 1 property inherited fromQObject
  • 1 public slot inherited fromQObject
  • 1 signal inherited fromQObject
  • 1 static public member inherited fromQLayout
  • 7 static public members inherited fromQObject

Detailed Description

TheQBoxLayout class lines up child widgets horizontally or vertically.

QBoxLayout takes the space it gets (from its parent layout or from theparentWidget()), divides it up into a row of boxes, and makes each managed widget fill one box.

Horizontal box layout with five child widgets

If theQBoxLayout's orientation isQt::Horizontal the boxes are placed in a row, with suitable sizes. Each widget (or other box) will get at least its minimum size and at most its maximum size. Any excess space is shared according to the stretch factors (more about that below).

Vertical box layout with five child widgets

If theQBoxLayout's orientation isQt::Vertical, the boxes are placed in a column, again with suitable sizes.

The easiest way to create aQBoxLayout is to use one of the convenience classes, e.g.QHBoxLayout (forQt::Horizontal boxes) orQVBoxLayout (forQt::Vertical boxes). You can also use theQBoxLayout constructor directly, specifying its direction asLeftToRight,RightToLeft,TopToBottom, orBottomToTop.

If theQBoxLayout is not the top-level layout (i.e. it is not managing all of the widget's area and children), you must add it to its parent layout before you can do anything with it. The normal way to add a layout is by calling parentLayout->addLayout().

Once you have done this, you can add boxes to theQBoxLayout using one of four functions:

  • addWidget() to add a widget to theQBoxLayout and set the widget's stretch factor. (The stretch factor is along the row of boxes.)
  • addSpacing() to create an empty box; this is one of the functions you use to create nice and spacious dialogs. See below for ways to set margins.
  • addStretch() to create an empty, stretchable box.
  • addLayout() to add a box containing anotherQLayout to the row and set that layout's stretch factor.

UseinsertWidget(),insertSpacing(),insertStretch() orinsertLayout() to insert a box at a specified position in the layout.

QBoxLayout also includes two margin widths:

  • setContentsMargins() sets the width of the outer border on each side of the widget. This is the width of the reserved space along each of theQBoxLayout's four sides.
  • setSpacing() sets the width between neighboring boxes. (You can useaddSpacing() to get more space at a particular spot.)

The margin default is provided by the style. The default margin most Qt styles specify is 9 for child widgets and 11 for windows. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout.

To remove a widget from a layout, callremoveWidget(). CallingQWidget::hide() on a widget also effectively removes the widget from the layout untilQWidget::show() is called.

You will almost always want to useQVBoxLayout andQHBoxLayout rather thanQBoxLayout because of their convenient constructors.

See alsoQGridLayout,QStackedLayout, andLayout Management.

Member Type Documentation

enum QBoxLayout::Direction

This type is used to determine the direction of a box layout.

ConstantValueDescription
QBoxLayout::LeftToRight0Horizontal from left to right.
QBoxLayout::RightToLeft1Horizontal from right to left.
QBoxLayout::TopToBottom2Vertical from top to bottom.
QBoxLayout::BottomToTop3Vertical from bottom to top.

Member Function Documentation

QBoxLayout::QBoxLayout(Direction dir,QWidget * parent = 0)

Constructs a newQBoxLayout with directiondir and parent widgetparent.

See alsodirection().

QBoxLayout::~QBoxLayout()

Destroys this box layout.

The layout's widgets aren't destroyed.

[virtual]void QBoxLayout::addItem(QLayoutItem * item)

Reimplemented fromQLayout::addItem().

void QBoxLayout::addLayout(QLayout * layout,int stretch = 0)

Addslayout to the end of the box, with serial stretch factorstretch.

See alsoinsertLayout(),addItem(), andaddWidget().

void QBoxLayout::addSpacerItem(QSpacerItem * spacerItem)

AddsspacerItem to the end of this box layout.

This function was introduced in Qt 4.4.

See alsoaddSpacing() andaddStretch().

void QBoxLayout::addSpacing(int size)

Adds a non-stretchable space (aQSpacerItem) with sizesize to the end of this box layout.QBoxLayout provides default margin and spacing. This function adds additional space.

See alsoinsertSpacing(),addItem(), andQSpacerItem.

void QBoxLayout::addStretch(int stretch = 0)

Adds a stretchable space (aQSpacerItem) with zero minimum size and stretch factorstretch to the end of this box layout.

See alsoinsertStretch(),addItem(), andQSpacerItem.

void QBoxLayout::addStrut(int size)

Limits the perpendicular dimension of the box (e.g. height if the box isLeftToRight) to a minimum ofsize. Other constraints may increase the limit.

See alsoaddItem().

void QBoxLayout::addWidget(QWidget * widget,int stretch = 0,Qt::Alignment alignment = 0)

Addswidget to the end of this box layout, with a stretch factor ofstretch and alignmentalignment.

The stretch factor applies only in thedirection of theQBoxLayout, and is relative to the other boxes and widgets in thisQBoxLayout. Widgets and boxes with higher stretch factors grow more.

If the stretch factor is 0 and nothing else in theQBoxLayout has a stretch factor greater than zero, the space is distributed according to theQWidget:sizePolicy() of each widget that's involved.

The alignment is specified byalignment. The default alignment is 0, which means that the widget fills the entire cell.

See alsoinsertWidget(),addItem(),addLayout(),addStretch(),addSpacing(), andaddStrut().

[virtual]int QBoxLayout::count() const

Reimplemented fromQLayout::count().

Direction QBoxLayout::direction() const

Returns the direction of the box.addWidget() andaddSpacing() work in this direction; the stretch stretches in this direction.

See alsosetDirection(),QBoxLayout::Direction,addWidget(), andaddSpacing().

[virtual]Qt::Orientations QBoxLayout::expandingDirections() const

Reimplemented fromQLayoutItem::expandingDirections().

[virtual]bool QBoxLayout::hasHeightForWidth() const

Reimplemented fromQLayoutItem::hasHeightForWidth().

[virtual]int QBoxLayout::heightForWidth(int w) const

Reimplemented fromQLayoutItem::heightForWidth().

[protected]void QBoxLayout::insertItem(int index,QLayoutItem * item)

Insertsitem into this box layout at positionindex. Ifindex is negative, the item is added at the end.

See alsoaddItem(),insertWidget(),insertLayout(),insertStretch(), andinsertSpacing().

void QBoxLayout::insertLayout(int index,QLayout * layout,int stretch = 0)

Insertslayout at positionindex, with stretch factorstretch. Ifindex is negative, the layout is added at the end.

layout becomes a child of the box layout.

See alsoaddLayout() andinsertItem().

void QBoxLayout::insertSpacerItem(int index,QSpacerItem * spacerItem)

InsertsspacerItem at positionindex, with zero minimum size and stretch factor. Ifindex is negative the space is added at the end.

This function was introduced in Qt 4.4.

See alsoaddSpacerItem(),insertStretch(), andinsertSpacing().

void QBoxLayout::insertSpacing(int index,int size)

Inserts a non-stretchable space (aQSpacerItem) at positionindex, with sizesize. Ifindex is negative the space is added at the end.

The box layout has default margin and spacing. This function adds additional space.

See alsoaddSpacing(),insertItem(), andQSpacerItem.

void QBoxLayout::insertStretch(int index,int stretch = 0)

Inserts a stretchable space (aQSpacerItem) at positionindex, with zero minimum size and stretch factorstretch. Ifindex is negative the space is added at the end.

See alsoaddStretch(),insertItem(), andQSpacerItem.

void QBoxLayout::insertWidget(int index,QWidget * widget,int stretch = 0,Qt::Alignment alignment = 0)

Insertswidget at positionindex, with stretch factorstretch and alignmentalignment. Ifindex is negative, the widget is added at the end.

The stretch factor applies only in thedirection of theQBoxLayout, and is relative to the other boxes and widgets in thisQBoxLayout. Widgets and boxes with higher stretch factors grow more.

If the stretch factor is 0 and nothing else in theQBoxLayout has a stretch factor greater than zero, the space is distributed according to theQWidget:sizePolicy() of each widget that's involved.

The alignment is specified byalignment. The default alignment is 0, which means that the widget fills the entire cell.

See alsoaddWidget() andinsertItem().

[virtual]void QBoxLayout::invalidate()

Reimplemented fromQLayoutItem::invalidate().

Resets cached information.

[virtual]QLayoutItem * QBoxLayout::itemAt(int index) const

Reimplemented fromQLayout::itemAt().

[virtual]QSize QBoxLayout::maximumSize() const

Reimplemented fromQLayoutItem::maximumSize().

[virtual]int QBoxLayout::minimumHeightForWidth(int w) const

Reimplemented fromQLayoutItem::minimumHeightForWidth().

[virtual]QSize QBoxLayout::minimumSize() const

Reimplemented fromQLayoutItem::minimumSize().

void QBoxLayout::setDirection(Direction direction)

Sets the direction of this layout todirection.

See alsodirection().

[virtual]void QBoxLayout::setGeometry(constQRect & r)

Reimplemented fromQLayoutItem::setGeometry().

void QBoxLayout::setSpacing(int spacing)

ReimplementsQLayout::setSpacing(). Sets the spacing property tospacing.

See alsoQLayout::setSpacing() andspacing().

void QBoxLayout::setStretch(int index,int stretch)

Sets the stretch factor at positionindex. tostretch.

This function was introduced in Qt 4.5.

See alsostretch().

bool QBoxLayout::setStretchFactor(QWidget * widget,int stretch)

Sets the stretch factor forwidget tostretch and returns true ifwidget is found in this layout (not including child layouts); otherwise returns false.

See alsosetAlignment().

bool QBoxLayout::setStretchFactor(QLayout * layout,int stretch)

This is an overloaded function.

Sets the stretch factor for the layoutlayout tostretch and returns true iflayout is found in this layout (not including child layouts); otherwise returns false.

[virtual]QSize QBoxLayout::sizeHint() const

Reimplemented fromQLayoutItem::sizeHint().

int QBoxLayout::spacing() const

ReimplementsQLayout::spacing(). If the spacing property is valid, that value is returned. Otherwise, a value for the spacing property is computed and returned. Since layout spacing in a widget is style dependent, if the parent is a widget, it queries the style for the (horizontal or vertical) spacing of the layout. Otherwise, the parent is a layout, and it queries the parent layout for the spacing().

See alsoQLayout::spacing() andsetSpacing().

int QBoxLayout::stretch(int index) const

Returns the stretch factor at positionindex.

This function was introduced in Qt 4.5.

See alsosetStretch().

[virtual]QLayoutItem * QBoxLayout::takeAt(int index)

Reimplemented fromQLayout::takeAt().

© 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