Eneboo - Documentación para desarrolladores
Tipos públicos | Métodos públicos | Métodos protegidos | Amigas
Referencia de la Clase QBoxLayout

The QBoxLayout class lines up child widgets horizontally or vertically. Más...

#include <qlayout.h>

Diagrama de herencias de QBoxLayout
QLayout QLayout QLayoutItem QObject QLayoutItem QObject QLayoutItem QObject QLayoutItem QObject QHBoxLayout QHBoxLayout QVBoxLayout QVBoxLayout

Lista de todos los miembros.

Tipos públicos

enum  Direction {
  LeftToRight, RightToLeft, TopToBottom, BottomToTop,
  Down = TopToBottom, Up = BottomToTop, LeftToRight, RightToLeft,
  TopToBottom, BottomToTop, Down = TopToBottom, Up = BottomToTop
}
enum  Direction {
  LeftToRight, RightToLeft, TopToBottom, BottomToTop,
  Down = TopToBottom, Up = BottomToTop, LeftToRight, RightToLeft,
  TopToBottom, BottomToTop, Down = TopToBottom, Up = BottomToTop
}

Métodos públicos

 QBoxLayout (QWidget *parent, Direction, int border=0, int spacing=-1, const char *name=0)
 QBoxLayout (QLayout *parentLayout, Direction, int spacing=-1, const char *name=0)
 QBoxLayout (Direction, int spacing=-1, const char *name=0)
 ~QBoxLayout ()
void addItem (QLayoutItem *)
Direction direction () const
void setDirection (Direction)
void addSpacing (int size)
void addStretch (int stretch=0)
void addWidget (QWidget *, int stretch=0, int alignment=0)
void addLayout (QLayout *layout, int stretch=0)
void addStrut (int)
void insertSpacing (int index, int size)
void insertStretch (int index, int stretch=0)
void insertWidget (int index, QWidget *widget, int stretch=0, int alignment=0)
void insertLayout (int index, QLayout *layout, int stretch=0)
bool setStretchFactor (QWidget *, int stretch)
bool setStretchFactor (QLayout *l, int stretch)
QSize sizeHint () const
QSize minimumSize () const
QSize maximumSize () const
bool hasHeightForWidth () const
int heightForWidth (int) const
int minimumHeightForWidth (int) const
QSizePolicy::ExpandData expanding () const
void invalidate ()
QLayoutIterator iterator ()
void setGeometry (const QRect &)
int findWidget (QWidget *w)
 QBoxLayout (QWidget *parent, Direction, int border=0, int spacing=-1, const char *name=0)
 QBoxLayout (QLayout *parentLayout, Direction, int spacing=-1, const char *name=0)
 QBoxLayout (Direction, int spacing=-1, const char *name=0)
 ~QBoxLayout ()
void addItem (QLayoutItem *)
Direction direction () const
void setDirection (Direction)
void addSpacing (int size)
void addStretch (int stretch=0)
void addWidget (QWidget *, int stretch=0, int alignment=0)
void addLayout (QLayout *layout, int stretch=0)
void addStrut (int)
void insertSpacing (int index, int size)
void insertStretch (int index, int stretch=0)
void insertWidget (int index, QWidget *widget, int stretch=0, int alignment=0)
void insertLayout (int index, QLayout *layout, int stretch=0)
bool setStretchFactor (QWidget *, int stretch)
bool setStretchFactor (QLayout *l, int stretch)
QSize sizeHint () const
QSize minimumSize () const
QSize maximumSize () const
bool hasHeightForWidth () const
int heightForWidth (int) const
int minimumHeightForWidth (int) const
QSizePolicy::ExpandData expanding () const
void invalidate ()
QLayoutIterator iterator ()
void setGeometry (const QRect &)
int findWidget (QWidget *w)

Métodos protegidos

void insertItem (int index, QLayoutItem *)
void insertItem (int index, QLayoutItem *)

Amigas

class QDockWindow

Descripción detallada

The QBoxLayout class lines up child widgets horizontally or vertically.

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

qhbox-m.png Horizontal box with five child widgets

If the QBoxLayout's orientation is 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).

qvbox-m.png Vertical box with five child widgets

If the QBoxLayout's orientation is Vertical, the boxes are placed in a column, again with suitable sizes.

The easiest way to create a QBoxLayout is to use one of the convenience classes, e.g. QHBoxLayout (for Horizontal boxes) or QVBoxLayout (for Vertical boxes). You can also use the QBoxLayout constructor directly, specifying its direction as LeftToRight, Down, RightToLeft or Up.

If the QBoxLayout 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 the QBoxLayout using one of four functions:

addWidget() to add a widget to the QBoxLayout 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 another QLayout to the row and set that layout's stretch factor.

Use insertWidget(), insertSpacing(), insertStretch() or insertLayout() to insert a box at a specified position in the layout.

QBoxLayout also includes two margin widths:

setMargin() sets the width of the outer border. This is the width of the reserved space along each of the QBoxLayout's four sides. setSpacing() sets the width between neighboring boxes. (You can use addSpacing() to get more space at a particular spot.)

The margin defaults to 0. The spacing defaults to the same as the margin width for a top-level layout, or to the same as the parent layout. Both are parameters to the constructor.

To remove a widget from a layout, call remove(). Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.

You will almost always want to use QVBoxLayout and QHBoxLayout rather than QBoxLayout because of their convenient constructors.

Ver también:
QGrid Layout Overview

Documentación de las enumeraciones miembro de la clase

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

LeftToRight Horizontal, from left to right RightToLeft Horizontal, from right to left TopToBottom Vertical, from top to bottom Down The same as TopToBottom BottomToTop Vertical, from bottom to top Up The same as BottomToTop

Valores de enumeraciones:
LeftToRight 
RightToLeft 
TopToBottom 
BottomToTop 
Down 
Up 
LeftToRight 
RightToLeft 
TopToBottom 
BottomToTop 
Down 
Up 
Valores de enumeraciones:
LeftToRight 
RightToLeft 
TopToBottom 
BottomToTop 
Down 
Up 
LeftToRight 
RightToLeft 
TopToBottom 
BottomToTop 
Down 
Up 

Documentación del constructor y destructor

QBoxLayout::QBoxLayout ( QWidget parent,
Direction  d,
int  margin = 0,
int  spacing = -1,
const char *  name = 0 
)

Constructs a new QBoxLayout with direction d and main widget parent. parent may not be 0.

The margin is the number of pixels between the edge of the widget and its managed children. The spacing is the default number of pixels between neighboring children. If spacing is -1 the value of margin is used for spacing.

name is the internal object name.

Ver también:
direction()
QBoxLayout::QBoxLayout ( QLayout parentLayout,
Direction  d,
int  spacing = -1,
const char *  name = 0 
)

Constructs a new QBoxLayout called name, with direction d, and inserts it into parentLayout.

The spacing is the default number of pixels between neighboring children. If spacing is -1, the layout will inherit its parent's spacing().

QBoxLayout::QBoxLayout ( Direction  d,
int  spacing = -1,
const char *  name = 0 
)

Constructs a new QBoxLayout called name, with direction d.

If spacing is -1, the layout will inherit its parent's spacing(); otherwise spacing is used.

You must insert this box into another layout.

QBoxLayout::~QBoxLayout ( )

Destroys this box layout.

The layout's widgets aren't destroyed.

QBoxLayout::QBoxLayout ( QWidget parent,
Direction  ,
int  border = 0,
int  spacing = -1,
const char *  name = 0 
)
QBoxLayout::QBoxLayout ( QLayout parentLayout,
Direction  ,
int  spacing = -1,
const char *  name = 0 
)
QBoxLayout::QBoxLayout ( Direction  ,
int  spacing = -1,
const char *  name = 0 
)
QBoxLayout::~QBoxLayout ( )

Documentación de las funciones miembro

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

Adds item to the end of this box layout.

Implementa QLayout.

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

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

The ownership of item is transferred to the layout, and it's the layout's responsibility to delete it.

Implementa QLayout.

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

Adds layout to the end of the box, with serial stretch factor stretch.

When a layout is constructed with another layout as its parent, you don't need to call addLayout(); the child layout is automatically added to the parent layout as it is constructed.

Ver también:
insertLayout(), setAutoAdd(), addWidget(), addSpacing()
void QBoxLayout::addSpacing ( int  size)

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

Ver también:
insertSpacing(), addStretch()
void QBoxLayout::addSpacing ( int  size)
void QBoxLayout::addStretch ( int  stretch = 0)

Adds a stretchable space with zero minimum size and stretch factor stretch to the end of this box layout.

Ver también:
addSpacing()
void QBoxLayout::addStretch ( int  stretch = 0)
void QBoxLayout::addStrut ( int  size)

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

void QBoxLayout::addStrut ( int  )
void QBoxLayout::addWidget ( QWidget ,
int  stretch = 0,
int  alignment = 0 
)
void QBoxLayout::addWidget ( QWidget widget,
int  stretch = 0,
int  alignment = 0 
)

Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.

The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more.

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

Alignment is specified by alignment which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.

From Qt 3.0, the alignment parameter is interpreted more aggressively than in previous versions of Qt. A non-default alignment now indicates that the widget should not grow to fill the available space, but should be sized according to sizeHint().

Ver también:
insertWidget(), setAutoAdd(), addLayout(), addSpacing()
QBoxLayout::Direction QBoxLayout::direction ( ) const [inline]

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

Ver también:
QBoxLayout::Direction addWidget() addSpacing()
Direction QBoxLayout::direction ( ) const [inline]
QSizePolicy::ExpandData QBoxLayout::expanding ( ) const [virtual]

Returns whether this layout can make use of more space than sizeHint(). A value of Vertical or Horizontal means that it wants to grow in only one dimension, whereas BothDirections means that it wants to grow in both dimensions.

Reimplementado de QLayout.

QSizePolicy::ExpandData QBoxLayout::expanding ( ) const [virtual]

Returns whether this layout can make use of more space than sizeHint(). A value of Vertical or Horizontal means that it wants to grow in only one dimension, whereas BothDirections means that it wants to grow in both dimensions.

The default implementation returns BothDirections.

Reimplementado de QLayout.

int QBoxLayout::findWidget ( QWidget w)
int QBoxLayout::findWidget ( QWidget w)

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

Returns the index of w, or -1 if w is not found.

bool QBoxLayout::hasHeightForWidth ( ) const [virtual]

Returns TRUE if this layout's preferred height depends on its width; otherwise returns FALSE.

Reimplementado de QLayoutItem.

bool QBoxLayout::hasHeightForWidth ( ) const [virtual]

Returns TRUE if this layout's preferred height depends on its width; otherwise returns FALSE. The default implementation returns FALSE.

Reimplement this function in layout managers that support height for width.

Ver también:
heightForWidth(), QWidget::heightForWidth()

Reimplementado de QLayoutItem.

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

Returns the layout's preferred height when it is w pixels wide.

Reimplementado de QLayoutItem.

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

Returns the preferred height for this layout item, given the width w.

The default implementation returns -1, indicating that the preferred height is independent of the width of the item. Using the function hasHeightForWidth() will typically be much faster than calling this function and testing for -1.

Reimplement this function in layout managers that support height for width. A typical implementation will look like this:

        int MyLayout::heightForWidth( int w ) const
        {
            if ( cache_dirty || cached_width != w ) {
                // not all C++ compilers support "mutable"
                MyLayout *that = (MyLayout*)this;
                int h = calculateHeightForWidth( w );
                that->cached_hfw = h;
                return h;
            }
            return cached_hfw;
        }

Caching is strongly recommended; without it layout will take exponential time.

Ver también:
hasHeightForWidth()

Reimplementado de QLayoutItem.

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

Inserts item into this box layout at position index. If index is negative, the item is added at the end.

Atención:
Does not call QLayout::insertChildLayout() if item is a QLayout.
Ver también:
addItem(), findWidget()
void QBoxLayout::insertLayout ( int  index,
QLayout layout,
int  stretch = 0 
)
void QBoxLayout::insertLayout ( int  index,
QLayout layout,
int  stretch = 0 
)

Inserts layout at position index, with stretch factor stretch. If index is negative, the layout is added at the end.

layout becomes a child of the box layout.

Ver también:
setAutoAdd(), insertWidget(), insertSpacing()
void QBoxLayout::insertSpacing ( int  index,
int  size 
)
void QBoxLayout::insertSpacing ( int  index,
int  size 
)

Inserts a non-stretchable space at position index, with size size. If index is negative the space is added at the end.

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

Ver también:
insertStretch()
void QBoxLayout::insertStretch ( int  index,
int  stretch = 0 
)

Inserts a stretchable space at position index, with zero minimum size and stretch factor stretch. If index is negative the space is added at the end.

Ver también:
insertSpacing()
void QBoxLayout::insertStretch ( int  index,
int  stretch = 0 
)
void QBoxLayout::insertWidget ( int  index,
QWidget widget,
int  stretch = 0,
int  alignment = 0 
)

Inserts widget at position index, with stretch factor stretch and alignment alignment. If index is negative, the widget is added at the end.

The stretch factor applies only in the direction of the QBoxLayout, and is relative to the other boxes and widgets in this QBoxLayout. Widgets and boxes with higher stretch factors grow more.

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

Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.

From Qt 3.0, the alignment parameter is interpreted more aggressively than in previous versions of Qt. A non-default alignment now indicates that the widget should not grow to fill the available space, but should be sized according to sizeHint().

Ver también:
setAutoAdd(), insertLayout(), insertSpacing()
void QBoxLayout::insertWidget ( int  index,
QWidget widget,
int  stretch = 0,
int  alignment = 0 
)
void QBoxLayout::invalidate ( ) [virtual]

Resets cached information.

Reimplementado de QLayout.

void QBoxLayout::invalidate ( ) [virtual]

Invalidates cached information. Reimplementations must call this.

Reimplementado de QLayout.

QLayoutIterator QBoxLayout::iterator ( ) [virtual]

Implementa QLayout.

QLayoutIterator QBoxLayout::iterator ( ) [virtual]

Implemented in subclasses to return an iterator that iterates over this layout's children.

A typical implementation will be:

        QLayoutIterator MyLayout::iterator()
        {
            QGLayoutIterator *i = new MyLayoutIterator( internal_data );
            return QLayoutIterator( i );
        }

where MyLayoutIterator is a subclass of QGLayoutIterator.

Implementa QLayout.

QSize QBoxLayout::maximumSize ( ) const [virtual]

Returns the maximum size needed by this box layout.

Reimplementado de QLayout.

QSize QBoxLayout::maximumSize ( ) const [virtual]

Returns the maximum size of this layout. This is the largest size that the layout can have while still respecting the specifications. Does not include what's needed by margin() or menuBar().

The default implementation allows unlimited resizing.

Reimplementado de QLayout.

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

Returns the minimum size needed by this box layout.

Reimplementado de QLayout.

QSize QBoxLayout::minimumSize ( ) const [virtual]

Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications. Does not include what's needed by margin() or menuBar().

The default implementation allows unlimited resizing.

Reimplementado de QLayout.

void QBoxLayout::setDirection ( Direction  direction)

Sets the direction of this layout to direction.

void QBoxLayout::setDirection ( Direction  )
void QBoxLayout::setGeometry ( const QRect r) [virtual]

Resizes managed widgets within the rectangle r.

Implementa QLayout.

void QBoxLayout::setGeometry ( const QRect r) [virtual]

This function is reimplemented in subclasses to perform layout.

The default implementation maintains the geometry() information given by rect r. Reimplementors must call this function.

Implementa QLayout.

bool QBoxLayout::setStretchFactor ( QLayout l,
int  stretch 
)
bool QBoxLayout::setStretchFactor ( QLayout l,
int  stretch 
)

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Sets the stretch factor for the layout l to stretch and returns TRUE if l is found in this layout (not including child layouts); otherwise returns FALSE.

bool QBoxLayout::setStretchFactor ( QWidget w,
int  stretch 
)

Sets the stretch factor for widget w to stretch and returns TRUE if w is found in this layout (not including child layouts); otherwise returns FALSE.

bool QBoxLayout::setStretchFactor ( QWidget ,
int  stretch 
)
QSize QBoxLayout::sizeHint ( ) const [virtual]

Implemented in subclasses to return the preferred size of this item.

Implementa QLayoutItem.

QSize QBoxLayout::sizeHint ( ) const [virtual]

Returns the preferred size of this box layout.

Implementa QLayoutItem.


Documentación de las funciones relacionadas y clases amigas

QDockWindow [friend]

La documentación para esta clase fue generada a partir de los siguientes ficheros:
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'