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

The QGridLayout class lays out widgets in a grid. Más...

#include <qlayout.h>

Diagrama de herencias de QGridLayout
QLayout QLayout QLayoutItem QObject QLayoutItem QObject QLayoutItem QObject QLayoutItem QObject QDesignerGridLayout QDockWindowGridLayout

Lista de todos los miembros.

Tipos públicos

enum  Corner {
  TopLeft, TopRight, BottomLeft, BottomRight,
  TopLeft, TopRight, BottomLeft, BottomRight
}
enum  Corner {
  TopLeft, TopRight, BottomLeft, BottomRight,
  TopLeft, TopRight, BottomLeft, BottomRight
}

Métodos públicos

 QGridLayout (QWidget *parent, int nRows=1, int nCols=1, int border=0, int spacing=-1, const char *name=0)
 QGridLayout (int nRows=1, int nCols=1, int spacing=-1, const char *name=0)
 QGridLayout (QLayout *parentLayout, int nRows=1, int nCols=1, int spacing=-1, const char *name=0)
 ~QGridLayout ()
QSize sizeHint () const
QSize minimumSize () const
QSize maximumSize () const
virtual void setRowStretch (int row, int stretch)
virtual void setColStretch (int col, int stretch)
int rowStretch (int row) const
int colStretch (int col) const
void setRowSpacing (int row, int minSize)
void setColSpacing (int col, int minSize)
int rowSpacing (int row) const
int colSpacing (int col) const
int numRows () const
int numCols () const
QRect cellGeometry (int row, int col) const
bool hasHeightForWidth () const
int heightForWidth (int) const
int minimumHeightForWidth (int) const
QSizePolicy::ExpandData expanding () const
void invalidate ()
void addItem (QLayoutItem *)
void addItem (QLayoutItem *item, int row, int col)
void addMultiCell (QLayoutItem *, int fromRow, int toRow, int fromCol, int toCol, int align=0)
void addWidget (QWidget *, int row, int col, int align=0)
void addMultiCellWidget (QWidget *, int fromRow, int toRow, int fromCol, int toCol, int align=0)
void addLayout (QLayout *layout, int row, int col)
void addMultiCellLayout (QLayout *layout, int fromRow, int toRow, int fromCol, int toCol, int align=0)
void addRowSpacing (int row, int minsize)
void addColSpacing (int col, int minsize)
void expand (int rows, int cols)
void setOrigin (Corner)
Corner origin () const
QLayoutIterator iterator ()
void setGeometry (const QRect &)
 QGridLayout (QWidget *parent, int nRows=1, int nCols=1, int border=0, int spacing=-1, const char *name=0)
 QGridLayout (int nRows=1, int nCols=1, int spacing=-1, const char *name=0)
 QGridLayout (QLayout *parentLayout, int nRows=1, int nCols=1, int spacing=-1, const char *name=0)
 ~QGridLayout ()
QSize sizeHint () const
QSize minimumSize () const
QSize maximumSize () const
virtual void setRowStretch (int row, int stretch)
virtual void setColStretch (int col, int stretch)
int rowStretch (int row) const
int colStretch (int col) const
void setRowSpacing (int row, int minSize)
void setColSpacing (int col, int minSize)
int rowSpacing (int row) const
int colSpacing (int col) const
int numRows () const
int numCols () const
QRect cellGeometry (int row, int col) const
bool hasHeightForWidth () const
int heightForWidth (int) const
int minimumHeightForWidth (int) const
QSizePolicy::ExpandData expanding () const
void invalidate ()
void addItem (QLayoutItem *)
void addItem (QLayoutItem *item, int row, int col)
void addMultiCell (QLayoutItem *, int fromRow, int toRow, int fromCol, int toCol, int align=0)
void addWidget (QWidget *, int row, int col, int align=0)
void addMultiCellWidget (QWidget *, int fromRow, int toRow, int fromCol, int toCol, int align=0)
void addLayout (QLayout *layout, int row, int col)
void addMultiCellLayout (QLayout *layout, int fromRow, int toRow, int fromCol, int toCol, int align=0)
void addRowSpacing (int row, int minsize)
void addColSpacing (int col, int minsize)
void expand (int rows, int cols)
void setOrigin (Corner)
Corner origin () const
QLayoutIterator iterator ()
void setGeometry (const QRect &)

Métodos protegidos

bool findWidget (QWidget *w, int *r, int *c)
void add (QLayoutItem *, int row, int col)
bool findWidget (QWidget *w, int *r, int *c)
void add (QLayoutItem *, int row, int col)

Descripción detallada

The QGridLayout class lays out widgets in a grid.

QGridLayout takes the space made available to it (by its parent layout or by the mainWidget()), divides it up into rows and columns, and puts each widget it manages into the correct cell.

Columns and rows behave identically; we will discuss columns, but there are equivalent functions for rows.

Each column has a minimum width and a stretch factor. The minimum width is the greatest of that set using addColSpacing() and the minimum width of each widget in that column. The stretch factor is set using setColStretch() and determines how much of the available space the column will get over and above its necessary minimum.

Normally, each managed widget or layout is put into a cell of its own using addWidget(), addLayout() or by the auto-add facility. It is also possible for a widget to occupy multiple cells using addMultiCellWidget(). If you do this, QGridLayout will guess how to distribute the size over the columns/rows (based on the stretch factors).

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.

This illustration shows a fragment of a dialog with a five-column, three-row grid (the grid is shown overlaid in magenta):

gridlayout.png

Columns 0, 2 and 4 in this dialog fragment are made up of a QLabel, a QLineEdit, and a QListBox. Columns 1 and 3 are placeholders made with addColSpacing(). Row 0 consists of three QLabel objects, row 1 of three QLineEdit objects and row 2 of three QListBox objects. We used placeholder columns (1 and 3) to get the right amount of space between the columns.

Note that the columns and rows are not equally wide or tall. If you want two columns to have the same width, you must set their minimum widths and stretch factors to be the same yourself. You do this using addColSpacing() and setColStretch().

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

Once you have added your layout you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addLayout() and addMultiCellWidget().

QGridLayout also includes two margin widths: the border and the spacing. The border is the width of the reserved space along each of the QGridLayout's four sides. The spacing is the width of the automatically allocated spacing between neighboring boxes.

Both the border and the spacing are parameters of the constructor and default to 0.

Ver también:
QGrid, Layout Overview

Documentación de las enumeraciones miembro de la clase

This enum identifies which corner is the origin (0, 0) of the layout.

TopLeft the top-left corner TopRight the top-right corner BottomLeft the bottom-left corner BottomRight the bottom-right corner

Valores de enumeraciones:
TopLeft 
TopRight 
BottomLeft 
BottomRight 
TopLeft 
TopRight 
BottomLeft 
BottomRight 

Reimplementado de Qt.

This enum type specifies a corner in a rectangle: TopLeft top left corner TopRight top right corner BottomLeft bottom left corner BottomRight bottom right corner

Valores de enumeraciones:
TopLeft 
TopRight 
BottomLeft 
BottomRight 
TopLeft 
TopRight 
BottomLeft 
BottomRight 

Reimplementado de Qt.


Documentación del constructor y destructor

QGridLayout::QGridLayout ( QWidget parent,
int  nRows = 1,
int  nCols = 1,
int  margin = 0,
int  space = -1,
const char *  name = 0 
)

Constructs a new QGridLayout with nRows rows, nCols columns and parent widget, parent. parent may not be 0. The grid layout is called name.

margin is the number of pixels between the edge of the widget and its managed children. space is the default number of pixels between cells. If space is -1, the value of margin is used.

QGridLayout::QGridLayout ( int  nRows = 1,
int  nCols = 1,
int  spacing = -1,
const char *  name = 0 
)

Constructs a new grid with nRows rows and nCols columns. If spacing is -1, this QGridLayout inherits its parent's spacing(); otherwise spacing is used. The grid layout is called name.

You must insert this grid into another layout. You can insert widgets and layouts into this layout at any time, but laying out will not be performed before this is inserted into another layout.

QGridLayout::QGridLayout ( QLayout parentLayout,
int  nRows = 1,
int  nCols = 1,
int  spacing = -1,
const char *  name = 0 
)

Constructs a new grid that is placed inside parentLayout with nRows rows and nCols columns. If spacing is -1, this QGridLayout inherits its parent's spacing(); otherwise spacing is used. The grid layout is called name.

This grid is placed according to parentLayout's default placement rules.

QGridLayout::~QGridLayout ( )

Destroys the grid layout. Geometry management is terminated if this is a top-level grid.

The layout's widgets aren't destroyed.

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

Documentación de las funciones miembro

void QGridLayout::add ( QLayoutItem item,
int  row,
int  col 
) [protected]

Adds item at position row, col. The layout takes ownership of the item.

void QGridLayout::add ( QLayoutItem ,
int  row,
int  col 
) [protected]
void QGridLayout::addColSpacing ( int  col,
int  minsize 
)

Sets the minimum width of column col to minsize pixels.

Use setColSpacing() instead.

void QGridLayout::addColSpacing ( int  col,
int  minsize 
)
void QGridLayout::addItem ( QLayoutItem item,
int  row,
int  col 
)

Adds item at position row, col. The layout takes ownership of the item.

void QGridLayout::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 QGridLayout::addItem ( QLayoutItem item) [virtual]

Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Adds item to the next free position of this layout.

Implementa QLayout.

void QGridLayout::addItem ( QLayoutItem item,
int  row,
int  col 
)
void QGridLayout::addLayout ( QLayout layout,
int  row,
int  col 
)

Places the layout at position (row, col) in the grid. The top-left position is (0, 0).

layout becomes a child of the grid layout.

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:
addMultiCellLayout()
void QGridLayout::addLayout ( QLayout layout,
int  row,
int  col 
)
void QGridLayout::addMultiCell ( QLayoutItem item,
int  fromRow,
int  toRow,
int  fromCol,
int  toCol,
int  alignment = 0 
)

Adds the item to the cell grid, spanning multiple rows/columns.

The cell will span from fromRow, fromCol to toRow, toCol. 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.

void QGridLayout::addMultiCell ( QLayoutItem ,
int  fromRow,
int  toRow,
int  fromCol,
int  toCol,
int  align = 0 
)
void QGridLayout::addMultiCellLayout ( QLayout layout,
int  fromRow,
int  toRow,
int  fromCol,
int  toCol,
int  alignment = 0 
)

Adds the layout layout to the cell grid, spanning multiple rows/columns. The cell will span from fromRow, fromCol to toRow, toCol.

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.

A non-zero alignment indicates that the layout should not grow to fill the available space but should be sized according to sizeHint().

layout becomes a child of the grid layout.

Ver también:
addLayout()
void QGridLayout::addMultiCellLayout ( QLayout layout,
int  fromRow,
int  toRow,
int  fromCol,
int  toCol,
int  align = 0 
)
void QGridLayout::addMultiCellWidget ( QWidget w,
int  fromRow,
int  toRow,
int  fromCol,
int  toCol,
int  alignment = 0 
)

Adds the widget w to the cell grid, spanning multiple rows/columns. The cell will span from fromRow, fromCol to toRow, toCol.

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.

A non-zero alignment indicates that the widget should not grow to fill the available space but should be sized according to sizeHint().

Ver también:
addWidget()

Reimplementado en QDesignerGridLayout.

void QGridLayout::addMultiCellWidget ( QWidget ,
int  fromRow,
int  toRow,
int  fromCol,
int  toCol,
int  align = 0 
)

Reimplementado en QDesignerGridLayout.

void QGridLayout::addRowSpacing ( int  row,
int  minsize 
)

Sets the minimum height of row row to minsize pixels.

Use setRowSpacing() instead.

void QGridLayout::addRowSpacing ( int  row,
int  minsize 
)
void QGridLayout::addWidget ( QWidget w,
int  row,
int  col,
int  alignment = 0 
)

Adds the widget w to the cell grid at row, col. The top-left position is (0, 0) by default.

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.

You should not call this if you have enabled the auto-add facility of the layout.

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:
addMultiCellWidget()

Reimplementado en QDesignerGridLayout.

void QGridLayout::addWidget ( QWidget ,
int  row,
int  col,
int  align = 0 
)

Reimplementado en QDesignerGridLayout.

QRect QGridLayout::cellGeometry ( int  row,
int  col 
) const

Returns the geometry of the cell with row row and column col in the grid. Returns an invalid rectangle if row or col is outside the grid.

Atención:
in the current version of Qt this function does not return valid results until setGeometry() has been called, i.e. after the mainWidget() is visible.
QRect QGridLayout::cellGeometry ( int  row,
int  col 
) const
int QGridLayout::colSpacing ( int  col) const
int QGridLayout::colSpacing ( int  col) const

Returns the column spacing for column col.

Ver también:
setColSpacing()
int QGridLayout::colStretch ( int  col) const

Returns the stretch factor for column col.

Ver también:
setColStretch()
int QGridLayout::colStretch ( int  col) const
void QGridLayout::expand ( int  rows,
int  cols 
)
void QGridLayout::expand ( int  nRows,
int  nCols 
)

Expands this grid so that it will have nRows rows and nCols columns. Will not shrink the grid. You should not need to call this function because QGridLayout expands automatically as new items are inserted.

QSizePolicy::ExpandData QGridLayout::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.

Reimplementado en QDockWindowGridLayout.

QSizePolicy::ExpandData QGridLayout::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.

Reimplementado en QDockWindowGridLayout.

bool QGridLayout::findWidget ( QWidget w,
int r,
int c 
) [protected]
bool QGridLayout::findWidget ( QWidget w,
int row,
int col 
) [protected]

Searches for widget w in this layout (not including child layouts). If w is found, it sets row and col to the row and column and returns TRUE; otherwise returns FALSE.

Note: if a widget spans multiple rows/columns, the top-left cell is returned.

bool QGridLayout::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.

bool QGridLayout::hasHeightForWidth ( ) const [virtual]

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

Reimplementado de QLayoutItem.

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

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

Reimplementado de QLayoutItem.

int QGridLayout::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 QGridLayout::invalidate ( ) [virtual]

Resets cached information.

Reimplementado de QLayout.

void QGridLayout::invalidate ( ) [virtual]

Invalidates cached information. Reimplementations must call this.

Reimplementado de QLayout.

QLayoutIterator QGridLayout::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.

QLayoutIterator QGridLayout::iterator ( ) [virtual]

Implementa QLayout.

QSize QGridLayout::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.

QSize QGridLayout::maximumSize ( ) const [virtual]

Returns the maximum size needed by this grid.

Reimplementado de QLayout.

int QGridLayout::minimumHeightForWidth ( int  w) const
int QGridLayout::minimumHeightForWidth ( int  ) const
QSize QGridLayout::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.

QSize QGridLayout::minimumSize ( ) const [virtual]

Returns the minimum size needed by this grid.

Reimplementado de QLayout.

int QGridLayout::numCols ( ) const
int QGridLayout::numCols ( ) const

Returns the number of columns in this grid.

int QGridLayout::numRows ( ) const

Returns the number of rows in this grid.

int QGridLayout::numRows ( ) const
Corner QGridLayout::origin ( ) const
QGridLayout::Corner QGridLayout::origin ( ) const

Returns the corner that's used for the grid's origin, i.e. for position (0, 0).

int QGridLayout::rowSpacing ( int  row) const

Returns the row spacing for row row.

Ver también:
setRowSpacing()
int QGridLayout::rowSpacing ( int  row) const
int QGridLayout::rowStretch ( int  row) const
int QGridLayout::rowStretch ( int  row) const

Returns the stretch factor for row row.

Ver también:
setRowStretch()
void QGridLayout::setColSpacing ( int  col,
int  minSize 
)

Sets the minimum width of column col to minSize pixels.

Ver también:
colSpacing(), setRowSpacing()
void QGridLayout::setColSpacing ( int  col,
int  minSize 
)
virtual void QGridLayout::setColStretch ( int  col,
int  stretch 
) [virtual]
void QGridLayout::setColStretch ( int  col,
int  stretch 
) [virtual]

Sets the stretch factor of column col to stretch. The first column is number 0.

The stretch factor is relative to the other columns in this grid. Columns with a higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other column in this table can grow at all, the column may still grow.

Ver también:
colStretch(), addColSpacing(), setRowStretch()
void QGridLayout::setGeometry ( const QRect r) [virtual]

Resizes managed widgets within the rectangle r.

Implementa QLayout.

void QGridLayout::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.

void QGridLayout::setOrigin ( Corner  )
void QGridLayout::setOrigin ( Corner  c)

Sets the grid's origin corner, i.e. position (0, 0), to c.

void QGridLayout::setRowSpacing ( int  row,
int  minSize 
)
void QGridLayout::setRowSpacing ( int  row,
int  minSize 
)

Sets the minimum height of row row to minSize pixels.

Ver también:
rowSpacing(), setColSpacing()
void QGridLayout::setRowStretch ( int  row,
int  stretch 
) [virtual]

Sets the stretch factor of row row to stretch. The first row is number 0.

The stretch factor is relative to the other rows in this grid. Rows with a higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other row in this table can grow at all, the row may still grow.

Ver también:
rowStretch(), setRowSpacing(), setColStretch()
virtual void QGridLayout::setRowStretch ( int  row,
int  stretch 
) [virtual]
QSize QGridLayout::sizeHint ( ) const [virtual]

Returns the preferred size of this grid.

Implementa QLayoutItem.

QSize QGridLayout::sizeHint ( ) const [virtual]

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

Implementa QLayoutItem.


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'