QSint Library  0.2.2
Public Slots | Public Member Functions | Protected Member Functions | List of all members
QSint::TabListMenu Class Reference

Class representing drop-down menu of QTabWidget's tabs. More...

#include <tablistmenu.h>

Inherits QMenu.

Public Slots

void setAllowIcons (bool allow=true)
 
virtual void createMenu ()
 
virtual void switchTab (QAction *from)
 

Public Member Functions

 TabListMenu (QWidget *parent=0)
 
void setTabs (QTabWidget *tabs)
 
QTabWidget * tabs () const
 
bool iconsAllowed () const
 

Protected Member Functions

virtual void doCreateMenu (QTabWidget *tabs)
 
virtual void doCreateMenuItem (int index, bool current, QAction *item, QTabWidget *tabs)
 
virtual void doSwitchTab (QAction *from, QTabWidget *tabs)
 

Detailed Description

Class representing drop-down menu of QTabWidget's tabs.

Since
0.2
TabListMenu.png
An example of TabListMenu

TabListMenu makes it easy to provide drop-down menu with a list of opened tabs, which highlights the current one and allows to switch between the tabs by choosing the corresponding menu items.

Typycally you'd like to create a corner button at the right (or left) QTabWidget's edge and assign the menu to it using setTabs().

An example how to use TabListMenu with QTabWidget and corner button. Only 3 lines of code needed.

// assume that we're now in MainWindow constructor.
// ui->tabWidget is QTabWidget.
// tbTabsDropList is QToolButton.
ui->setupUi(this);
// create TabListMenu
// assing ui->tabWidget to the tabMenu
tabMenu->setTabs(ui->tabWidget);
// create corner button
QToolButton *tbTabsDropList = new QToolButton(this);
tbTabsDropList->setPopupMode(QToolButton::InstantPopup);
ui->tabWidget->setCornerWidget(tbTabsDropList);
// assing tabMenu to the tbTabsDropList
tbTabsDropList->setMenu(tabMenu);

You can also easily customize menu's items by subclassing TabListMenu's methods doCreateMenuItem() or/and doCreateMenu().

An example how to customize 1st menu item by naming it "Main Page" and adding a separator after it.

// a subclass of TabListMenu
class MyTabListMenu : public QSint::TabListMenu
{
public:
MyTabListMenu(QWidget *parent = 0) : QSint::TabListMenu(parent)
{
}
protected:
// reimplement this method to customize menu items
virtual void doCreateMenuItem(int index, bool current, QAction *item, QTabWidget *tabs)
{
// call TabListMenu's doCreateMenuItem() first.
// this will create and initialize menu's entry item.
QSint::TabListMenu::doCreateMenuItem(index, current, item, tabs);
// check tab index and change item's text if it's the very first tab.
// also add a separator afterwards.
if (index == 0) {
item->setText(tr("Main Page"));
addSeparator();
}
}
};

Constructor & Destructor Documentation

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

Constructor.

Member Function Documentation

void QSint::TabListMenu::createMenu ( )
virtualslot

This slot is called internally when QMenu::aboutToShow() signal is emitted. You can reimplement it in order to customize TabListMenu behavior. By default it clears the menu and calls doCreateMenu().

void QSint::TabListMenu::doCreateMenu ( QTabWidget *  tabs)
protectedvirtual

This function is called internally before menu is shown. You can reimplement it in order to populate the menu manually.

Default implementation calls doCreateMenuItem() for each tab of QTabWidget tabs separately.

void QSint::TabListMenu::doCreateMenuItem ( int  index,
bool  current,
QAction *  item,
QTabWidget *  tabs 
)
protectedvirtual

This function is called from doCreateMenu() for each tab separately. You can reimplement it in order to change item's representation.

Default implementation creates QAction item of QTabWidget tabs's tab with index index. If this tab is current one, then current is set to true.

In order to perform tab switching, it sets item's data value to the corresponding tab index. This value is being checked in doSwitchTab() when the user chooses an item from the menu.

void QSint::TabListMenu::doSwitchTab ( QAction *  from,
QTabWidget *  tabs 
)
protectedvirtual

This function is called internally when QAction from of QTabWidget tabs was triggered by the user. You can reimplement it in order to switch the tab manually.

Default implementation switches current tab of tabs to from->data().

bool QSint::TabListMenu::iconsAllowed ( ) const
inline

Returns true if icons are allowed, false otherwise.

void QSint::TabListMenu::setAllowIcons ( bool  allow = true)
inlineslot

When allow is true, allows icons to be shown in the menu (enabled by default).

void QSint::TabListMenu::setTabs ( QTabWidget *  tabs)

The most important fuction which assigns QTabWidget tabs to the menu.

void QSint::TabListMenu::switchTab ( QAction *  from)
virtualslot

This slot is called when menu item from has been selected by the user. You can reimplement it in order to customize TabListMenu behavior. By default it calls doSwitchTab().

QTabWidget* QSint::TabListMenu::tabs ( ) const
inline

Returns QTabWidget assigned to the menu or 0 if no QTabWidget assigned.


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

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