PDA

View Full Version : show Tabbar only if there are more than 1 tabs.



momesana
23rd September 2007, 12:29
Is there an easy way to display the tabbar only when there are more than 1 tabs? Right now, I've a subclassed QTabBar and redefined tabInserted, tabRemoved to check the numbers of tabs and toggle the visibility of the Tabbar accordingly. Is there a more simple way to do this? Maybe a member function of QTabWidget where I can activate/deactivate this behaviour? I could'nt find anything.


#ifndef TABBAR_H
#define TABBAR_H

#include <QTabBar>
class TabBar : public QTabBar
{
Q_OBJECT
public:
TabBar(QWidget *parent=0) : QTabBar(parent){}
private:
void toggleVisibility()
{
(count() <= 1) ? hide() : show();
}
protected:
void tabInserted(int) { toggleVisibility(); }
void tabRemoved(int) { toggleVisibility(); }
};
#endif

wysota
23rd September 2007, 18:11
Subclass QTabWidget (not QTabBar) and show() or hide() the tabBar() from within tabInserted() or tabRemoved().

momesana
23rd September 2007, 20:07
Thanks. Works fine and there is one less class to clutter my code.