Results 1 to 3 of 3

Thread: show Tabbar only if there are more than 1 tabs.

  1. #1
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default show Tabbar only if there are more than 1 tabs.

    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.
    Qt Code:
    1. #ifndef TABBAR_H
    2. #define TABBAR_H
    3.  
    4. #include <QTabBar>
    5. class TabBar : public QTabBar
    6. {
    7. Q_OBJECT
    8. public:
    9. TabBar(QWidget *parent=0) : QTabBar(parent){}
    10. private:
    11. void toggleVisibility()
    12. {
    13. (count() <= 1) ? hide() : show();
    14. }
    15. protected:
    16. void tabInserted(int) { toggleVisibility(); }
    17. void tabRemoved(int) { toggleVisibility(); }
    18. };
    19. #endif
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: show Tabbar only if there are more than 1 tabs.

    Subclass QTabWidget (not QTabBar) and show() or hide() the tabBar() from within tabInserted() or tabRemoved().

  3. The following user says thank you to wysota for this useful post:

    momesana (23rd September 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: show Tabbar only if there are more than 1 tabs.

    Thanks. Works fine and there is one less class to clutter my code.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.