QSint::ActionBox Class Reference

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

#include <actionbox.h>

Public Member Functions

 ActionBox (const QPixmap &icon, const QString &headerText, QWidget *parent=nullptr)
 Constructor. More...
 
 ActionBox (const QString &headerText, QWidget *parent=nullptr)
 Constructor. More...
 
 ActionBox (QWidget *parent=nullptr)
 Constructor. More...
 
void addLayout (QLayout *l)
 Adds layout l to the default layout. More...
 
void addWidget (QWidget *w, QLayout *l=nullptr)
 Adds widget w to the layout. More...
 
QLayoutcreateHBoxLayout ()
 Creates empty horizontal layout. More...
 
ActionLabelcreateItem (const QPixmap &icon, const QString &text, QLayout *l=nullptr)
 Adds an action with icon and text to the ActionBox and returns action item. More...
 
ActionLabelcreateItem (const QString &text=QString(), QLayout *l=nullptr)
 Adds an action with text to the ActionBox and returns action item. More...
 
ActionLabelcreateItem (QAction *action, QLayout *l=nullptr)
 Creates action item from the action and returns it. More...
 
QList< ActionLabel * > createItems (QList< QAction * > actions)
 Creates action items from the actions list and returns the list of action items. More...
 
QSpacerItem * createSpacer (QLayout *l=nullptr)
 Adds a spacer and returns spacer item. More...
 
ActionLabelheader () const
 Returns header item of the ActionBox. More...
 
QPixmap icon () const
 Returns icon of the ActionBox. More...
 
QLayoutitemLayout () const
 Returns default layout used for actions (typically it's QVBoxLayout). More...
 
virtual QSize minimumSizeHint () const
 
void setIcon (const QPixmap &icon)
 Sets icon of the ActionBox to icon. More...
 

Protected Member Functions

void init ()
 

Protected Attributes

QVBoxLayout * dataLayout
 
ActionLabelheaderLabel
 
QLabeliconLabel
 

Properties

ActionLabel header
 
QPixmap icon
 

Detailed Description

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

Since
0.2
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("3rd 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

◆ ActionBox() [1/3]

QSint::ActionBox::ActionBox ( QWidget parent = nullptr)
explicit

Constructor.

References init().

◆ ActionBox() [2/3]

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

Constructor.

References headerLabel, and init().

◆ ActionBox() [3/3]

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

Constructor.

References headerLabel, icon, init(), and setIcon().

Member Function Documentation

◆ addLayout()

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

Adds layout l to the default layout.

References dataLayout.

◆ addWidget()

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

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.

References createSpacer(), and dataLayout.

◆ createHBoxLayout()

QLayout * QSint::ActionBox::createHBoxLayout ( )

Creates empty horizontal layout.

Use this function to arrange action items into a row.

References createSpacer(), and dataLayout.

Referenced by createItems().

◆ createItem() [1/3]

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

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.

References createItem(), and icon.

◆ createItem() [2/3]

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

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

References createSpacer(), and dataLayout.

◆ createItem() [3/3]

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

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

References createItem().

Referenced by Gui::TaskView::TaskGroup::actionEvent(), createItem(), createItems(), and init().

◆ createItems()

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

References createHBoxLayout(), and createItem().

◆ createSpacer()

QSpacerItem * QSint::ActionBox::createSpacer ( QLayout l = nullptr)

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.

References dataLayout.

Referenced by addWidget(), createHBoxLayout(), and createItem().

◆ header()

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

Returns header item of the ActionBox.

◆ icon()

◆ init()

void QSint::ActionBox::init ( void  )
protected

◆ itemLayout()

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

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

◆ minimumSizeHint()

QSize QSint::ActionBox::minimumSizeHint ( ) const
virtual

◆ setIcon()

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

Sets icon of the ActionBox to icon.

References icon, and iconLabel.

Referenced by ActionBox().

Member Data Documentation

◆ dataLayout

QVBoxLayout* QSint::ActionBox::dataLayout
protected

◆ headerLabel

ActionLabel* QSint::ActionBox::headerLabel
protected

Referenced by ActionBox(), and init().

◆ iconLabel

QLabel* QSint::ActionBox::iconLabel
protected

Referenced by icon(), init(), and setIcon().

Property Documentation

◆ header

ActionLabel QSint::ActionBox::header
read

◆ icon


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