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

QLayout Class

TheQLayout class is the base class of geometry managers.More...

Header:#include <QLayout>
Inherits:QObject andQLayoutItem
Inherited By:

QBoxLayout,QFormLayout,QGridLayout, andQStackedLayout

Public Types

enumSizeConstraint { SetDefaultConstraint, SetFixedSize, SetMinimumSize, SetMaximumSize, SetMinAndMaxSize, SetNoConstraint }

Properties

Public Functions

QLayout(QWidget * parent)
QLayout()
boolactivate()
virtual voidaddItem(QLayoutItem * item) = 0
voidaddWidget(QWidget * w)
QMarginscontentsMargins() const
QRectcontentsRect() const
virtual intcount() const = 0
voidgetContentsMargins(int * left, int * top, int * right, int * bottom) const
virtual intindexOf(QWidget * widget) const
boolisEnabled() const
virtual QLayoutItem *itemAt(int index) const = 0
QWidget *menuBar() const
QWidget *parentWidget() const
voidremoveItem(QLayoutItem * item)
voidremoveWidget(QWidget * widget)
boolsetAlignment(QWidget * w, Qt::Alignment alignment)
voidsetAlignment(Qt::Alignment alignment)
boolsetAlignment(QLayout * l, Qt::Alignment alignment)
voidsetContentsMargins(int left, int top, int right, int bottom)
voidsetContentsMargins(const QMargins & margins)
voidsetEnabled(bool enable)
voidsetMenuBar(QWidget * widget)
voidsetSizeConstraint(SizeConstraint)
voidsetSpacing(int)
SizeConstraintsizeConstraint() const
intspacing() const
virtual QLayoutItem *takeAt(int index) = 0
voidupdate()

Reimplemented Public Functions

virtual Qt::OrientationsexpandingDirections() const
virtual QRectgeometry() const
virtual voidinvalidate()
virtual boolisEmpty() const
virtual QLayout *layout()
virtual QSizemaximumSize() const
virtual QSizeminimumSize() const
virtual voidsetGeometry(const QRect & r)

Static Public Members

QSizeclosestAcceptableSize(const QWidget * widget, const QSize & size)
  • 7 static public members inherited fromQObject

Protected Functions

voidaddChildLayout(QLayout * l)
voidaddChildWidget(QWidget * w)
QRectalignmentRect(const QRect & r) const

Reimplemented Protected Functions

virtual voidchildEvent(QChildEvent * e)
  • 8 protected functions inherited fromQObject

Additional Inherited Members

Detailed Description

TheQLayout class is the base class of geometry managers.

This is an abstract base class inherited by the concrete classesQBoxLayout,QGridLayout,QFormLayout, andQStackedLayout.

For users ofQLayout subclasses or ofQMainWindow there is seldom any need to use the basic functions provided byQLayout, such assetSizeConstraint() orsetMenuBar(). SeeLayout Management for more information.

To make your own layout manager, implement the functionsaddItem(),sizeHint(),setGeometry(),itemAt() andtakeAt(). You should also implementminimumSize() to ensure your layout isn't resized to zero size if there is too little space. To support children whose heights depend on their widths, implementhasHeightForWidth() andheightForWidth(). See theBorder Layout andFlow Layout examples for more information about implementing custom layout managers.

Geometry management stops when the layout manager is deleted.

See alsoQLayoutItem,Layout Management,Basic Layouts Example,Border Layout Example, andFlow Layout Example.

Member Type Documentation

enum QLayout::SizeConstraint

The possible values are:

ConstantValueDescription
QLayout::SetDefaultConstraint0The main widget's minimum size is set tominimumSize(), unless the widget already has a minimum size.
QLayout::SetFixedSize3The main widget's size is set tosizeHint(); it cannot be resized at all.
QLayout::SetMinimumSize2The main widget's minimum size is set tominimumSize(); it cannot be smaller.
QLayout::SetMaximumSize4The main widget's maximum size is set tomaximumSize(); it cannot be larger.
QLayout::SetMinAndMaxSize5The main widget's minimum size is set tominimumSize() and its maximum size is set tomaximumSize().
QLayout::SetNoConstraint1The widget is not constrained.

See alsosetSizeConstraint().

Property Documentation

sizeConstraint :SizeConstraint

This property holds the resize mode of the layout.

The default mode isSetDefaultConstraint.

Access functions:

SizeConstraintsizeConstraint() const
voidsetSizeConstraint(SizeConstraint)

spacing :int

This property holds the spacing between widgets inside the layout.

If no value is explicitly set, the layout's spacing is inherited from the parent layout, or from the style settings for the parent widget.

ForQGridLayout andQFormLayout, it is possible to set different horizontal and vertical spacings usingsetHorizontalSpacing() andsetVerticalSpacing(). In that case, spacing() returns -1.

Access functions:

intspacing() const
voidsetSpacing(int)

See alsocontentsRect(),getContentsMargins(),QStyle::layoutSpacing(), andQStyle::pixelMetric().

Member Function Documentation

QLayout::QLayout(QWidget * parent)

Constructs a new top-levelQLayout, with parentparent.parent may not be 0.

There can be only one top-level layout for a widget. It is returned byQWidget::layout().

QLayout::QLayout()

Constructs a new childQLayout.

This layout has to be inserted into another layout before geometry management will work.

bool QLayout::activate()

Redoes the layout forparentWidget() if necessary.

You should generally not need to call this because it is automatically called at the most appropriate times. It returns true if the layout was redone.

See alsoupdate() andQWidget::updateGeometry().

[protected]void QLayout::addChildLayout(QLayout * l)

This function is called fromaddLayout() orinsertLayout() functions in subclasses to add layoutl as a sub-layout.

The only scenario in which you need to call it directly is if you implement a custom layout that supports nested layouts.

See alsoQBoxLayout::addLayout(),QBoxLayout::insertLayout(), andQGridLayout::addLayout().

[protected]void QLayout::addChildWidget(QWidget * w)

This function is called fromaddWidget() functions in subclasses to addw as a managed widget of a layout.

Ifw is already managed by a layout, this function will give a warning and removew from that layout. This function must therefore be called before addingw to the layout's data structure.

[pure virtual]void QLayout::addItem(QLayoutItem * item)

Implemented in subclasses to add anitem. How it is added is specific to each subclass.

This function is not usually called in application code. To add a widget to a layout, use theaddWidget() function; to add a child layout, use the addLayout() function provided by the relevantQLayout subclass.

Note: The ownership ofitem is transferred to the layout, and it's the layout's responsibility to delete it.

See alsoaddWidget(),QBoxLayout::addLayout(), andQGridLayout::addLayout().

void QLayout::addWidget(QWidget * w)

Adds widgetw to this layout in a manner specific to the layout. This function usesaddItem().

[protected]QRect QLayout::alignmentRect(constQRect & r) const

Returns the rectangle that should be covered when the geometry of this layout is set tor, provided that this layout supportssetAlignment().

The result is derived fromsizeHint() and expanding(). It is never larger thanr.

[virtual protected]void QLayout::childEvent(QChildEvent * e)

Reimplemented fromQObject::childEvent().

[static]QSize QLayout::closestAcceptableSize(constQWidget * widget, constQSize & size)

Returns a size that satisfies all size constraints onwidget, includingheightForWidth() and that is as close as possible tosize.

QMargins QLayout::contentsMargins() const

Returns the margins used around the layout.

By default,QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

This function was introduced in Qt 4.6.

See alsosetContentsMargins().

QRect QLayout::contentsRect() const

Returns the layout'sgeometry() rectangle, but taking into account the contents margins.

This function was introduced in Qt 4.3.

See alsosetContentsMargins() andgetContentsMargins().

[pure virtual]int QLayout::count() const

Must be implemented in subclasses to return the number of items in the layout.

See alsoitemAt().

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

Reimplemented fromQLayoutItem::expandingDirections().

Returns whether this layout can make use of more space thansizeHint(). A value ofQt::Vertical orQt::Horizontal means that it wants to grow in only one dimension, whereasQt::Vertical |Qt::Horizontal means that it wants to grow in both dimensions.

The default implementation returnsQt::Horizontal |Qt::Vertical. Subclasses reimplement it to return a meaningful value based on their child widgets'ssize policies.

See alsosizeHint().

[virtual]QRect QLayout::geometry() const

Reimplemented fromQLayoutItem::geometry().

See alsosetGeometry().

void QLayout::getContentsMargins(int * left,int * top,int * right,int * bottom) const

Extracts the left, top, right, and bottom margins used around the layout, and assigns them to *left, *top, *right, and *bottom (unless they are null pointers).

By default,QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

This function was introduced in Qt 4.3.

See alsosetContentsMargins(),QStyle::pixelMetric(),PM_LayoutLeftMargin,PM_LayoutTopMargin,PM_LayoutRightMargin, andPM_LayoutBottomMargin.

[virtual]int QLayout::indexOf(QWidget * widget) const

Searches for widgetwidget in this layout (not including child layouts).

Returns the index ofwidget, or -1 ifwidget is not found.

The default implementation iterates over all items usingitemAt()

[virtual]void QLayout::invalidate()

Reimplemented fromQLayoutItem::invalidate().

[virtual]bool QLayout::isEmpty() const

Reimplemented fromQLayoutItem::isEmpty().

bool QLayout::isEnabled() const

Returns true if the layout is enabled; otherwise returns false.

See alsosetEnabled().

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

Must be implemented in subclasses to return the layout item atindex. If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.

This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.

staticvoid paintLayout(QPainter*painter,QLayoutItem*item){QLayout*layout= item->layout();if (layout) {for (int i=0; i< layout->count();++i)            paintLayout(painter, layout->itemAt(i));    }    painter->drawRect(item->geometry());}void MyWidget::paintEvent(QPaintEvent*){QPainter painter(this);if (layout())        paintLayout(&painter, layout());}

See alsocount() andtakeAt().

[virtual]QLayout * QLayout::layout()

Reimplemented fromQLayoutItem::layout().

[virtual]QSize QLayout::maximumSize() const

Reimplemented fromQLayoutItem::maximumSize().

Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required byQWidget::setContentsMargins() ormenuBar().

The default implementation allows unlimited resizing.

QWidget * QLayout::menuBar() const

Returns the menu bar set for this layout, or 0 if no menu bar is set.

See alsosetMenuBar().

[virtual]QSize QLayout::minimumSize() const

Reimplemented fromQLayoutItem::minimumSize().

Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications.

The returned value doesn't include the space required byQWidget::setContentsMargins() ormenuBar().

The default implementation allows unlimited resizing.

QWidget * QLayout::parentWidget() const

Returns the parent widget of this layout, or 0 if this layout is not installed on any widget.

If the layout is a sub-layout, this function returns the parent widget of the parent layout.

See alsoparent().

void QLayout::removeItem(QLayoutItem * item)

Removes the layout itemitem from the layout. It is the caller's responsibility to delete the item.

Notice thatitem can be a layout (sinceQLayout inheritsQLayoutItem).

See alsoremoveWidget() andaddItem().

void QLayout::removeWidget(QWidget * widget)

Removes the widgetwidget from the layout. After this call, it is the caller's responsibility to give the widget a reasonable geometry or to put the widget back into a layout.

Note: The ownership ofwidget remains the same as when it was added.

See alsoremoveItem(),QWidget::setGeometry(), andaddWidget().

bool QLayout::setAlignment(QWidget * w,Qt::Alignment alignment)

Sets the alignment for widgetw toalignment and returns true ifw is found in this layout (not including child layouts); otherwise returns false.

void QLayout::setAlignment(Qt::Alignment alignment)

Sets the alignment of this item toalignment.

See alsoQLayoutItem::setAlignment().

bool QLayout::setAlignment(QLayout * l,Qt::Alignment alignment)

This is an overloaded function.

Sets the alignment for the layoutl toalignment and returns true ifl is found in this layout (not including child layouts); otherwise returns false.

void QLayout::setContentsMargins(int left,int top,int right,int bottom)

Sets theleft,top,right, andbottom margins to use around the layout.

By default,QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

This function was introduced in Qt 4.3.

See alsocontentsMargins(),getContentsMargins(),QStyle::pixelMetric(),PM_LayoutLeftMargin,PM_LayoutTopMargin,PM_LayoutRightMargin, andPM_LayoutBottomMargin.

void QLayout::setContentsMargins(constQMargins & margins)

Sets themargins to use around the layout.

By default,QLayout uses the values provided by the style. On most platforms, the margin is 11 pixels in all directions.

This function was introduced in Qt 4.6.

See alsocontentsMargins().

void QLayout::setEnabled(bool enable)

Enables this layout ifenable is true, otherwise disables it.

An enabled layout adjusts dynamically to changes; a disabled layout acts as if it did not exist.

By default all layouts are enabled.

See alsoisEnabled().

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

Reimplemented fromQLayoutItem::setGeometry().

See alsogeometry().

void QLayout::setMenuBar(QWidget * widget)

Tells the geometry manager to place the menu barwidget at the top ofparentWidget(), outsideQWidget::contentsMargins(). All child widgets are placed below the bottom edge of the menu bar.

See alsomenuBar().

[pure virtual]QLayoutItem * QLayout::takeAt(int index)

Must be implemented in subclasses to remove the layout item atindex from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is removed, other items will be renumbered.

The following code fragment shows a safe way to remove all items from a layout:

QLayoutItem*child;while ((child= layout->takeAt(0))!=0) {...delete child;}

See alsoitemAt() andcount().

void QLayout::update()

Updates the layout forparentWidget().

You should generally not need to call this because it is automatically called at the most appropriate times.

See alsoactivate() andinvalidate().

© 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