Policy that uses the Qt grid layout engine to provide a grid layout.This class provides a policy which is similar to QGraphicsGridLayout, with the advantage of allowing multiple policies and animation. You can use QGraphicsGridLayout instead to slightly reduce memory overhead if these advantages are not required.
More...
Inherits MAbstractLayoutPolicy.
List of all members.
Public Member Functions |
| MGridLayoutPolicy (MLayout *layout) |
virtual | ~MGridLayoutPolicy () |
int | rowCount () const |
int | columnCount () const |
void | setRowSpacing (int row, qreal spacing) |
qreal | rowSpacing (int row) const |
void | setColumnSpacing (int column, qreal spacing) |
qreal | columnSpacing (int column) const |
void | setRowAlignment (int row, Qt::Alignment alignment) |
Qt::Alignment | rowAlignment (int row) const |
void | setColumnAlignment (int column, Qt::Alignment alignment) |
Qt::Alignment | columnAlignment (int column) const |
QGraphicsLayoutItem * | itemAt (int row, int col) const |
void | addItem (QGraphicsLayoutItem *item, int row, int column, int rowSpan, int columnSpan, Qt::Alignment alignment=0) |
void | addItem (QGraphicsLayoutItem *item, int row, int column, Qt::Alignment alignment=0) |
void | setRowStretchFactor (int row, int stretch) |
int | rowStretchFactor (int row) const |
void | setColumnStretchFactor (int column, int stretch) |
int | columnStretchFactor (int column) const |
void | setRowMinimumHeight (int row, qreal height) |
qreal | rowMinimumHeight (int row) const |
void | setRowPreferredHeight (int row, qreal height) |
qreal | rowPreferredHeight (int row) const |
void | setRowMaximumHeight (int row, qreal height) |
qreal | rowMaximumHeight (int row) const |
void | setRowFixedHeight (int row, qreal height) |
void | setColumnMinimumWidth (int column, qreal width) |
qreal | columnMinimumWidth (int column) const |
void | setColumnPreferredWidth (int column, qreal width) |
qreal | columnPreferredWidth (int column) const |
void | setColumnMaximumWidth (int column, qreal width) |
qreal | columnMaximumWidth (int column) const |
void | setColumnFixedWidth (int column, qreal width) |
Qt::Alignment | alignment (QGraphicsLayoutItem *item) const |
void | setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment) |
Detailed Description
Policy that uses the Qt grid layout engine to provide a grid layout.
This class provides a policy which is similar to QGraphicsGridLayout, with the advantage of allowing multiple policies and animation. You can use QGraphicsGridLayout instead to slightly reduce memory overhead if these advantages are not required.
The following example adds items to the grid layout policy:
The result, with appropriate CSS styling, looks like:
- See also:
- DuiGridLayoutPolicy example
Limitations - equally-sized columns
It is difficult to create a grid layout with equally-sized columns, with both MGridLayoutPolicy and QGraphicsGridLayout. The current workaround is to manually set the preferred width of all the items inside the layout to the same width.
As an example, to layout items in two columns with equal widths:
We are working with Qt to try to find a better solution.
Using QGraphicsGridLayout instead
If you do not need animations or multiple policies, you can use QGraphicsGridLayout for same effect in less code. For example:
- See also:
- QGraphicsGridLayout example
Constructor & Destructor Documentation
MGridLayoutPolicy::MGridLayoutPolicy |
( |
MLayout * |
layout |
) |
[explicit] |
Constructs a grid layout policy.
- Parameters:
-
| layout | The layout to associate with. |
MGridLayoutPolicy::~MGridLayoutPolicy |
( |
|
) |
[virtual] |
Destructor to clean up engine.
Member Function Documentation
void MGridLayoutPolicy::addItem |
( |
QGraphicsLayoutItem * |
item, |
|
|
int |
row, |
|
|
int |
column, |
|
|
int |
rowSpan, |
|
|
int |
columnSpan, |
|
|
Qt::Alignment |
alignment = 0 | |
|
) |
| | |
Add an item at a position in the grid.
- Parameters:
-
| item | The item to add. |
| row | The row to add the item to. |
| column | The column to add the item to. |
| rowSpan | The number of cells the item spans in the row |
| columnSpan | The number of cells the item spans in the column |
| alignment | The alignment to use. |
void MGridLayoutPolicy::addItem |
( |
QGraphicsLayoutItem * |
item, |
|
|
int |
row, |
|
|
int |
column, |
|
|
Qt::Alignment |
alignment = 0 | |
|
) |
| | [inline] |
Add an item at a position in the grid.
- Parameters:
-
| item | The item to add. |
| row | The row to add the item to. |
| column | The column to add the item to. |
| alignment | The alignment to use. |
Returns the alignment for item. The default alignment is Qt::AlignCenter.
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 also:
- setAlignment()
Qt::Alignment MGridLayoutPolicy::columnAlignment |
( |
int |
column |
) |
const |
Get the default alignment for a whole column.
- Parameters:
-
| column | the row to get the alignment for |
- Returns:
- the default alignment in use
int MGridLayoutPolicy::columnCount |
( |
|
) |
const |
Get the number of columns.
- Returns:
- The number of columns.
qreal MGridLayoutPolicy::columnMaximumWidth |
( |
int |
column |
) |
const |
Returns the maximum width for column.
qreal MGridLayoutPolicy::columnMinimumWidth |
( |
int |
column |
) |
const |
Returns the minimum width for column.
qreal MGridLayoutPolicy::columnPreferredWidth |
( |
int |
column |
) |
const |
Returns the preferred width for column.
qreal MGridLayoutPolicy::columnSpacing |
( |
int |
column |
) |
const |
Get spacing for a single column.
- Parameters:
-
| column | The column to get the spacing for. |
- Returns:
- The spacing.
int MGridLayoutPolicy::columnStretchFactor |
( |
int |
column |
) |
const |
Returns the stretch factor for column.
Get an item.
Get the item found at the given position in the grid.
- Parameters:
-
| row | The row to query. |
| col | The column to query. |
- Returns:
- The item at the position or 0 if invalid/unset.
Qt::Alignment MGridLayoutPolicy::rowAlignment |
( |
int |
row |
) |
const |
Get the default alignment for a whole row.
- Parameters:
-
| row | the row to get the alignment for |
- Returns:
- the default alignment in use
int MGridLayoutPolicy::rowCount |
( |
|
) |
const |
Get the number of rows.
- Returns:
- The number of rows.
qreal MGridLayoutPolicy::rowMaximumHeight |
( |
int |
row |
) |
const |
Returns the maximum height for row.
qreal MGridLayoutPolicy::rowMinimumHeight |
( |
int |
row |
) |
const |
Returns the minimum height for row.
qreal MGridLayoutPolicy::rowPreferredHeight |
( |
int |
row |
) |
const |
Returns the preferred height for row.
qreal MGridLayoutPolicy::rowSpacing |
( |
int |
row |
) |
const |
Get spacing for a single row.
- Parameters:
-
| row | The row to get the spacing for. |
- Returns:
- The spacing.
int MGridLayoutPolicy::rowStretchFactor |
( |
int |
row |
) |
const |
Returns the stretch factor for row.
Sets the alignment of item to alignment. If item's alignment changes, the layout is automatically invalidated.
- See also:
- alignment(), invalidate()
void MGridLayoutPolicy::setColumnAlignment |
( |
int |
column, |
|
|
Qt::Alignment |
alignment | |
|
) |
| | |
Set the default alignment for a whole column. This value can be overridden on an item for item basis.
- Parameters:
-
| column | the column to set the default alignment for |
| alignment | the default alignment to use |
void MGridLayoutPolicy::setColumnFixedWidth |
( |
int |
column, |
|
|
qreal |
width | |
|
) |
| | |
Sets the fixed width of column to width.
void MGridLayoutPolicy::setColumnMaximumWidth |
( |
int |
column, |
|
|
qreal |
width | |
|
) |
| | |
Sets the maximum width of column to width.
void MGridLayoutPolicy::setColumnMinimumWidth |
( |
int |
column, |
|
|
qreal |
width | |
|
) |
| | |
Sets the minimum width for column to width.
void MGridLayoutPolicy::setColumnPreferredWidth |
( |
int |
column, |
|
|
qreal |
width | |
|
) |
| | |
Sets the preferred width for column to width.
void MGridLayoutPolicy::setColumnSpacing |
( |
int |
column, |
|
|
qreal |
spacing | |
|
) |
| | |
Set spacing for a single column.
- Parameters:
-
| column | The column to set the spacing for. |
| spacing | The spacing to use. |
void MGridLayoutPolicy::setColumnStretchFactor |
( |
int |
column, |
|
|
int |
stretch | |
|
) |
| | |
Sets the stretch factor for column.
void MGridLayoutPolicy::setRowAlignment |
( |
int |
row, |
|
|
Qt::Alignment |
alignment | |
|
) |
| | |
Set the default alignment for a whole row. This value can be overridden on an item for item basis.
- Parameters:
-
| row | the row to set the default alignment for |
| alignment | the default alignment to use |
void MGridLayoutPolicy::setRowFixedHeight |
( |
int |
row, |
|
|
qreal |
height | |
|
) |
| | |
Sets the fixed height for row to height.
void MGridLayoutPolicy::setRowMaximumHeight |
( |
int |
row, |
|
|
qreal |
height | |
|
) |
| | |
Sets the maximum height for row to height.
void MGridLayoutPolicy::setRowMinimumHeight |
( |
int |
row, |
|
|
qreal |
height | |
|
) |
| | |
Sets the minimum height for row to height.
void MGridLayoutPolicy::setRowPreferredHeight |
( |
int |
row, |
|
|
qreal |
height | |
|
) |
| | |
Sets the preferred height for row.
void MGridLayoutPolicy::setRowSpacing |
( |
int |
row, |
|
|
qreal |
spacing | |
|
) |
| | |
Set spacing for a single row.
- Parameters:
-
| row | The row to set the spacing for. |
| spacing | The spacing to use. |
void MGridLayoutPolicy::setRowStretchFactor |
( |
int |
row, |
|
|
int |
stretch | |
|
) |
| | |
Sets the stretch factor for row.