QSint Library  0.2.2
Public Member Functions | List of all members
QSint::ActionBox Class Reference

Class representing a panel of actions similar to Windows Vista/7 control panel items. More...

#include <actionbox.h>

Inherits QFrame.

Public Member Functions

 ActionBox (QWidget *parent=0)
 
 ActionBox (const QString &headerText, QWidget *parent=0)
 
 ActionBox (const QPixmap &icon, const QString &headerText, QWidget *parent=0)
 
void setIcon (const QPixmap &icon)
 
const QPixmap * icon () const
 
ActionLabel * header () const
 
ActionLabel * createItem (QAction *action, QLayout *l=0)
 
QList< ActionLabel * > createItems (QList< QAction * > actions)
 
ActionLabel * createItem (const QString &text="", QLayout *l=0)
 
ActionLabel * createItem (const QPixmap &icon, const QString &text, QLayout *l=0)
 
QSpacerItem * createSpacer (QLayout *l=0)
 
QLayout * createHBoxLayout ()
 
QLayout * itemLayout () const
 
void addLayout (QLayout *l)
 
void addWidget (QWidget *w, QLayout *l=0)
 

Detailed Description

Class representing a panel of actions similar to Windows Vista/7 control panel items.

Since
0.2
ActionBox.png
An example of ActionBox

ActionBox normally consists of an icon, clickable header and a list of actions. Every action can have own icon as well, provide tooltips and status tips, be clickable and checkable etc. i.e. behave like a normal ActionLabel.

ActionBox objects are easily customizable via CSS technology - you can get different look just by writing corresponding style sheet.

Usage of ActionBox in the application

  1. Create ActionBox using constructor (or in Designer as Promoted Objects). Icon and header text can be passed to the constructor as well. For example:
ActionBox *box1 = new ActionBox(":/icons/box1icon.png", "Header Text", this);
  1. ActionBox header itself is a clickable item (based on ActionLabel), so you can retrieve it and use, for example, to connect with a slot:
connect(box1->header(), SIGNAL(clicked()), this, SLOT(header1clicked()));
  1. To create an action, use one of createItem() functions. For example:
ActionLabel *action1 = box1->createItem(":/icons/action1icon.png", "Action1 Text");
connect(action1, SIGNAL(clicked()), this, SLOT(action1clicked()));
ActionLabel *action2 = box1->createItem(":/icons/action2icon.png", "Action2 Text");
connect(action2, SIGNAL(clicked()), this, SLOT(action2clicked()));

createItem() also allows to create an ActionLabel from already existing QAction:

QAction myAction3(":/icons/action3icon.png", "Action3 Text");
connect(myAction3, SIGNAL(clicked()), this, SLOT(action3clicked()));
ActionLabel *action3 = box1->createItem(myAction3);
  1. By default, actions are arranged vertically, one per row. In order to have more than one actions in a row, first add horizontal layout item using createHBoxLayout() function, and then pass it to the createItem() to create actions.
// create horizontal layout
QLayout *hbl1 = box1->createHBoxLayout();
// create actions using this layout
ActionLabel *action3 = box1->createItem(":/icons/action3icon.png", "1st action in row", hbl1);
ActionLabel *action4 = box1->createItem("2nd action in row", hbl1);
  1. Sometimes you would like to have a spacer between the items. Use createSpacer() function to insert an empty space into default or specified layout.
// create a spacer after two actions added before
box1->createSpacer(hbl1);
// create another action which will be preceded by the empty space (i.e. right-aligned)
ActionLabel *action5 = box1->createItem("3nd action in row", hbl1);
  1. You can insert arbitrary layout items and widgets into ActionBox using addLayout() and addWidgets() functions. Please note that ownership of these items transferred to ActionBox, so you must not delete them manually.

Customization of ActionBox via CSS

ActionBox items can be easily customized using CSS mechanism. Just create a new style and apply it to the ActionBox with setStyleSheet().

See the following example of the complete ActionBox customization. Note that QSint–ActionBox is used as a main class name. Headers are ActionLabels with property class='header'. Actions are ActionLabels with property class='action'.

// define a string representing CSS style
const char* ActionBoxNewStyle =
// customization of ActionBox
"QSint--ActionBox {"
"background-color: white;"
"border: 1px solid white;"
"border-radius: 3px;"
"text-align: left;"
"}"
"QSint--ActionBox:hover {"
"background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #F9FDFF, stop: 1 #EAF7FF);"
"border: 1px solid #DAF2FC;"
"}"
// customization of ActionBox's header
"QSint--ActionBox QSint--ActionLabel[class='header'] {"
"text-align: left;"
"font: 14px;"
"color: #006600;"
"background-color: transparent;"
"border: none;"
"}"
"QSint--ActionBox QSint--ActionLabel[class='header']:hover {"
"color: #00cc00;"
"text-decoration: underline;"
"}"
// customization of ActionBox's actions
"QSint--ActionBox QSint--ActionLabel[class='action'] {"
"background-color: transparent;"
"border: none;"
"color: #0033ff;"
"text-align: left;"
"font: 11px;"
"}"
"QSint--ActionBox QSint--ActionLabel[class='action']:hover {"
"color: #0099ff;"
"text-decoration: underline;"
"}"
"QSint--ActionBox QSint--ActionLabel[class='action']:on {"
"background-color: #ddeeff;"
"color: #006600;"
"}"
;
// apply the style
box1->setStyleSheet(ActionBoxNewStyle);

Constructor & Destructor Documentation

QSint::ActionBox::ActionBox ( QWidget *  parent = 0)
explicit

Constructor.

QSint::ActionBox::ActionBox ( const QString &  headerText,
QWidget *  parent = 0 
)
explicit

Constructor.

QSint::ActionBox::ActionBox ( const QPixmap &  icon,
const QString &  headerText,
QWidget *  parent = 0 
)
explicit

Constructor.

Member Function Documentation

void QSint::ActionBox::addLayout ( QLayout *  l)

Adds layout l to the default layout.

void QSint::ActionBox::addWidget ( QWidget *  w,
QLayout *  l = 0 
)

Adds widget w to the layout.

By default, widget is added to the default vertical layout. You can add widget to the specified layout passing it as l parameter.

QLayout * QSint::ActionBox::createHBoxLayout ( )

Creates empty horizontal layout.

Use this function to arrange action items into a row.

ActionLabel * QSint::ActionBox::createItem ( QAction *  action,
QLayout *  l = 0 
)

Creates action item from the action and returns it.

By default, action is added to the default vertical layout, i.e. subsequent calls of this function will create several actions arranged vertically, one below another.

You can add action to the specified layout passing it as l parameter. This allows to do custom actions arrangements, i.e. horizontal etc.

Since
0.2
ActionLabel * QSint::ActionBox::createItem ( const QString &  text = "",
QLayout *  l = 0 
)

Adds an action with text to the ActionBox and returns action item.

ActionLabel * QSint::ActionBox::createItem ( const QPixmap &  icon,
const QString &  text,
QLayout *  l = 0 
)

Adds an action with icon and text to the ActionBox and returns action item.

This function acts just like previous one. See the description above.

QList< ActionLabel * > QSint::ActionBox::createItems ( QList< QAction * >  actions)

Creates action items from the actions list and returns the list of action items.

Since
0.2
QSpacerItem * QSint::ActionBox::createSpacer ( QLayout *  l = 0)

Adds a spacer and returns spacer item.

By default, a spacer is added to the default vertical layout. You can add a spacer to the specified layout passing it as l parameter.

ActionLabel* QSint::ActionBox::header ( ) const
inline

Returns header item of the ActionBox.

const QPixmap* QSint::ActionBox::icon ( ) const
inline

Returns icon of the ActionBox.

QLayout* QSint::ActionBox::itemLayout ( ) const
inline

Returns default layout used for actions (typically it's QVBoxLayout).

void QSint::ActionBox::setIcon ( const QPixmap &  icon)

Sets icon of the ActionBox to icon.


The documentation for this class was generated from the following files:

© Sintegrial Technologies 2011-2014
http://www.sintegrial.com