Version: 9.12.0
QtxToolButton Class Reference

Drop-down tool button that behaves like a drop-down combo-box. More...

#include <QtxToolButton.h>

Inheritance diagram for QtxToolButton:
Inheritance graph

Public Slots

void clear ()
 Clear widget. More...
 
void setCurrentIndex (int)
 Set current item by given index. More...
 
void setCurrentText (const QString &)
 Set current item by given text. More...
 

Signals

void activated (int)
 
void activated (const QString &)
 
void currentIndexChanged (int)
 
void currentIndexChanged (const QString &)
 
void currentTextChanged (const QString &)
 

Public Member Functions

 QtxToolButton (QWidget *=0)
 Constructor. More...
 
virtual ~QtxToolButton ()
 Destructor. More...
 
int addItem (const QString &, const QVariant &=QVariant())
 Add an item with the given text, and containing the specified userData. The item is appended to the list of existing items. More...
 
int addItem (const QIcon &, const QString &, const QVariant &=QVariant())
 Add an item with the given icon and text, and containing the specified userData. The item is appended to the list of existing items. More...
 
void addItems (const QStringList &)
 Add items with given texts. Each item is appended to the list of existing items in turn. More...
 
int addSeparator (const QString &=QString())
 Add separator to the end of the items list. More...
 
int addSeparator (const QIcon &, const QString &)
 Add separator to the end of the items list. More...
 
void removeItem (int)
 Remove item with given index. More...
 
int count () const
 Get the number of items. More...
 
QVariant currentData () const
 Get data of the current item. More...
 
int currentIndex () const
 Get index of current item. More...
 
QString currentText () const
 Get text of current item. More...
 
QVariant itemData (int) const
 Get custom data of the item at given index. More...
 
QIcon itemIcon (int) const
 Get icon of the item at given index. More...
 
QString itemText (int) const
 Get text of the item at given index. More...
 
void setItemData (int, const QVariant &)
 Set custom data of the item at given index. More...
 
void setItemIcon (int, const QIcon &)
 Set icon of the item at given index. More...
 
void setItemText (int, const QString &)
 Set text of the item at given index. More...
 
int findText (const QString &)
 Search item with given text. More...
 

Protected Member Functions

void keyPressEvent (QKeyEvent *)
 Reimplemented from QToolButton::keyPressEvent(). Process key press event. More...
 
void wheelEvent (QWheelEvent *)
 Reimplemented from QToolButton::wheelEvent(). Process mouse wheel event. More...
 

Private Types

enum  Move {
  NoMove =0 , MoveUp , MoveDown , MoveFirst ,
  MoveLast
}
 

Private Slots

void actionTriggered (QAction *)
 Called when menu action is triggered. More...
 

Private Member Functions

void internalUpdate ()
 Update content of the widget. More...
 
QActionactionAt (int) const
 Get menu action at given index. More...
 
void moveIndex (Move)
 Move current index. More...
 
void emitCurrentChanged (bool, bool)
 Emit currentChanged() signal. More...
 

Detailed Description

Drop-down tool button that behaves like a drop-down combo-box.

In contrast to the standard combo box, QtxToolButton can show drop-down menu containing groups of items where each group has a separate title.

Member Enumeration Documentation

◆ Move

enum QtxToolButton::Move
private
Enumerator
NoMove 
MoveUp 
MoveDown 
MoveFirst 
MoveLast 

Constructor & Destructor Documentation

◆ QtxToolButton()

QtxToolButton::QtxToolButton ( QWidget parent = 0)

Constructor.

Parameters
parentParent widget.

References actionTriggered().

◆ ~QtxToolButton()

QtxToolButton::~QtxToolButton ( )
virtual

Destructor.

Member Function Documentation

◆ actionAt()

QAction * QtxToolButton::actionAt ( int  index) const
private

Get menu action at given index.

References count().

◆ actionTriggered

void QtxToolButton::actionTriggered ( QAction action)
privateslot

Called when menu action is triggered.

References currentIndex(), emitCurrentChanged(), and internalUpdate().

◆ activated [1/2]

void QtxToolButton::activated ( const QString &  )
signal

◆ activated [2/2]

void QtxToolButton::activated ( int  )
signal

◆ addItem() [1/2]

int QtxToolButton::addItem ( const QIcon &  icon,
const QString &  text,
const QVariant &  userData = QVariant() 
)

Add an item with the given icon and text, and containing the specified userData. The item is appended to the list of existing items.

Parameters
textItem's text.
iconItem's icon.
userDataItem's data.
Returns
Index of just added item.

References count(), emitCurrentChanged(), and internalUpdate().

◆ addItem() [2/2]

int QtxToolButton::addItem ( const QString &  text,
const QVariant &  userData = QVariant() 
)

Add an item with the given text, and containing the specified userData. The item is appended to the list of existing items.

Parameters
textItem's text.
userDataItem's data.
Returns
Index of just added item.

References count(), emitCurrentChanged(), and internalUpdate().

◆ addItems()

void QtxToolButton::addItems ( const QStringList &  texts)

Add items with given texts. Each item is appended to the list of existing items in turn.

Parameters
textsItems being added.

References count(), emitCurrentChanged(), and internalUpdate().

◆ addSeparator() [1/2]

int QtxToolButton::addSeparator ( const QIcon &  icon,
const QString &  text 
)

Add separator to the end of the items list.

Parameters
iconSeparator's icon.
textSeparator's text.
Returns
Index of just added item.

References actionAt(), and count().

◆ addSeparator() [2/2]

int QtxToolButton::addSeparator ( const QString &  text = QString())

Add separator to the end of the items list.

Parameters
textSeparator's text.
Returns
Index of just added item.

References actionAt(), and count().

◆ clear

void QtxToolButton::clear ( )
slot

Clear widget.

References emitCurrentChanged(), and internalUpdate().

◆ count()

int QtxToolButton::count ( ) const

Get the number of items.

Returns
Number of items.

◆ currentData()

QVariant QtxToolButton::currentData ( ) const

Get data of the current item.

Returns
Current item's data (invalid QVariant if list of items is empty or current item doesn't have data).

◆ currentIndex()

int QtxToolButton::currentIndex ( ) const

Get index of current item.

Returns
Current item's index; -1 if list of items is empty or if there's no current item.

◆ currentIndexChanged [1/2]

void QtxToolButton::currentIndexChanged ( const QString &  )
signal

◆ currentIndexChanged [2/2]

void QtxToolButton::currentIndexChanged ( int  )
signal

◆ currentText()

QString QtxToolButton::currentText ( ) const

Get text of current item.

Returns
Current item's text; null sting if list of items is empty or if there's no current item.

◆ currentTextChanged

void QtxToolButton::currentTextChanged ( const QString &  )
signal

◆ emitCurrentChanged()

void QtxToolButton::emitCurrentChanged ( bool  activate,
bool  changed 
)
private

Emit currentChanged() signal.

References activated(), currentIndexChanged(), and currentTextChanged().

◆ findText()

int QtxToolButton::findText ( const QString &  text)

Search item with given text.

Parameters
Item'stext.
Returns
Item's index; -1 if item is not found.

References actionAt(), and count().

◆ internalUpdate()

void QtxToolButton::internalUpdate ( )
private

Update content of the widget.

◆ itemData()

QVariant QtxToolButton::itemData ( int  index) const

Get custom data of the item at given index.

Parameters
indexItem's index.
Returns
Item's data (invalid QVariant if index is out of range).

References actionAt().

◆ itemIcon()

QIcon QtxToolButton::itemIcon ( int  index) const

Get icon of the item at given index.

Parameters
indexItem's index.
Returns
Item's icon.

References actionAt().

◆ itemText()

QString QtxToolButton::itemText ( int  index) const

Get text of the item at given index.

Parameters
indexItem's index.
Returns
Item's text.

References actionAt().

◆ keyPressEvent()

void QtxToolButton::keyPressEvent ( QKeyEvent *  e)
protected

Reimplemented from QToolButton::keyPressEvent(). Process key press event.

Parameters
eKey press event.

References MoveDown, MoveFirst, moveIndex(), MoveLast, MoveUp, and NoMove.

◆ moveIndex()

void QtxToolButton::moveIndex ( Move  move)
private

◆ removeItem()

void QtxToolButton::removeItem ( int  index)

Remove item with given index.

Parameters
indexIndex of item to be removed.

References actionAt(), count(), emitCurrentChanged(), and internalUpdate().

◆ setCurrentIndex

void QtxToolButton::setCurrentIndex ( int  index)
slot

Set current item by given index.

Parameters
indexItem's index.

References actionAt(), count(), currentIndex(), emitCurrentChanged(), and internalUpdate().

◆ setCurrentText

void QtxToolButton::setCurrentText ( const QString &  text)
slot

Set current item by given text.

Parameters
indexItem's index.

References findText(), and setCurrentIndex().

◆ setItemData()

void QtxToolButton::setItemData ( int  index,
const QVariant &  value 
)

Set custom data of the item at given index.

Parameters
indexItem's index.
valueItem's data.

References actionAt().

◆ setItemIcon()

void QtxToolButton::setItemIcon ( int  index,
const QIcon &  icon 
)

Set icon of the item at given index.

Parameters
indexItem's index.
iconItem's icon.

References actionAt(), and internalUpdate().

◆ setItemText()

void QtxToolButton::setItemText ( int  index,
const QString &  text 
)

Set text of the item at given index.

Parameters
indexItem's index.
textItem's text.

References actionAt(), currentTextChanged(), and internalUpdate().

◆ wheelEvent()

void QtxToolButton::wheelEvent ( QWheelEvent *  e)
protected

Reimplemented from QToolButton::wheelEvent(). Process mouse wheel event.

Parameters
eMouse wheel event.

References MoveDown, MoveFirst, moveIndex(), MoveLast, MoveUp, and NoMove.


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