Home · All Classes · Main Classes · Deprecated
Public Member Functions

MFlowLayoutPolicy Class Reference

This policy implements a simple flow layout.The items in the policy are organised into rows, starting from the top left. The size of each item is initially determined by its preferredSize(). Items with an expanding sizePolicy() are then expanded horizontally and vertically to fill any left over available space. More...

Inherits MAbstractLayoutPolicy.

List of all members.

Public Member Functions

 MFlowLayoutPolicy (MLayout *)
virtual ~MFlowLayoutPolicy ()
int rowCount ()
void setRowLimit (int rowLimit)
int rowLimit () const
Qt::Alignment alignment (QGraphicsLayoutItem *item) const
void setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment)

Detailed Description

This policy implements a simple flow layout.

The items in the policy are organised into rows, starting from the top left. The size of each item is initially determined by its preferredSize(). Items with an expanding sizePolicy() are then expanded horizontally and vertically to fill any left over available space.

The following example adds 10 labels to the flow layout policy:

    /* Create a MLayout that we set the policy for */
    MLayout *layout = new MLayout;

    MFlowLayoutPolicy *policy = new MFlowLayoutPolicy(layout);
    policy->setStyleName("example");
    policy->setRowLimit(2); //Only show 2 rows of items

    /* Add 20 items to the policy */
    for (int i = 1; i <= 20; ++i) {
        MLabel *label = new MLabel(QString("Item %1").arg(i));
        policy->addItem(label);
        policy->setAlignment(label, Qt::AlignCenter);
        label->setObjectName("item"); //Set CSS name, for styling
        label->setAlignment(Qt::AlignCenter);
        int random = i*10;
        label->setMaximumHeight(random);
        label->setMinimumHeight(random);
    }

The result, with appropriate CSS styling, looks like:

mflowlayoutpolicy.jpg
See also:
DuiFlowLayoutPolicy example

Using MButton in a MFlowLayoutPolicy

In the default CSS theme, a MButton has a fixed preferredWidth(), which does not depend on the text inside of it. This makes sense normally for buttons, but does not usually produce the desired behaviour in a flow layout. Every MButton in a MFlowLayoutPolicy will have the same width.


Constructor & Destructor Documentation

MFlowLayoutPolicy::MFlowLayoutPolicy ( MLayout layout  )  [explicit]

Constructs a flow layout policy.

MFlowLayoutPolicy::~MFlowLayoutPolicy (  )  [virtual]

Destroys a flow layout policy.

See also:
~MAbstractLayoutPolicy()

Member Function Documentation

Qt::Alignment MFlowLayoutPolicy::alignment ( QGraphicsLayoutItem item  )  const

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()
int MFlowLayoutPolicy::rowCount (  ) 

Return the number of rows that the items in the flow layout occupy in its current geometry.

The number of rows depends on the layout's current geometry, and the layout's geometry is not usually set until show() has been called. This will not be greater than rowLimit(), if set.

If the policy is not currently active, and has since been invalidated, this will return -1. If the policy is currently active and has been invalidated, this will trigger a relayout.

Returns:
The number of rows in the current geometry, or -1 if invalidated and not active
int MFlowLayoutPolicy::rowLimit (  )  const

Return the maximum number of rows to show.

No more than rowLimit rows will be shown. The rest of the items will be hidden.

The default is -1, indicating no row limit

void MFlowLayoutPolicy::setAlignment ( QGraphicsLayoutItem item,
Qt::Alignment  alignment 
)

Sets the alignment of item to alignment.

If item's alignment changes, the layout is automatically invalidated.

See also:
alignment()
void MFlowLayoutPolicy::setRowLimit ( int  rowLimit  ) 

Set the maximum number of rows to show.

No more than rowLimit rows will be shown. The rest of the items will be hidden.

The default is -1, indicating no row limit


Copyright © 2010 Nokia Corporation
MeeGo Touch