Results 1 to 1 of 1

Thread: reimplement tabBar() from QTabWidget in order to customize each tabs

  1. #1
    Join Date
    Jan 2012
    Posts
    29
    Thanks
    7

    Default Re: reimplement tabBar() from QTabWidget in order to customize each tabs

    Hi all,

    as per subject I am trying to customize my tabBar to have different buttons in each tab. Basically I would need to have closableTabs for all tabs but one. Looking for it in the web I would have found an easy way which consists in enable closebleTabs and then hide the button for a specific one:

    tabWidget->tabBar()->tabButton(0, QTabBar::RightSide)->hide();

    Sorry I posted the wrong code.


    Added after 7 minutes:


    Ok while writing I found the solution. Basically I create a derived class from QTabWidget

    Qt Code:
    1. #ifndef MYTABWIDGET_H
    2. #define MYTABWIDGET_H
    3.  
    4. #include <QTabWidget>
    5.  
    6. class MyTabWidget : public QTabWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit MyTabWidget(QWidget *parent = 0);
    11.  
    12. void hideButton(const int index); // this is a wrapper used to hide the button from tab at index
    13.  
    14. signals:
    15.  
    16. public slots:
    17.  
    18. };
    19.  
    20. #endif // MYTABWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "mytabwidget.h"
    2.  
    3. #include <QtGui>
    4. MyTabWidget::MyTabWidget(QWidget *parent) :
    5. QTabWidget(parent)
    6. {
    7.  
    8. setTabsClosable(true);
    9. }
    10.  
    11. void MyTabWidget::hideButton(const int index)
    12. {
    13.  
    14. tabBar()->tabButton(index, QTabBar::RightSide)->hide();
    15.  
    16. }
    To copy to clipboard, switch view to plain text mode 

    And then use the method to hide the button..

    Qt Code:
    1. ui->tabWidget->hideButton(1);
    To copy to clipboard, switch view to plain text mode 

    Thanks anyway, sometimes just writing your idea is helping :-)
    Last edited by dotjan; 9th August 2012 at 18:27.

Similar Threads

  1. Changing mouse cursor on QTabWidget only on the tabbar
    By si24803 in forum Qt Programming
    Replies: 0
    Last Post: 3rd April 2012, 12:48
  2. QTabWidget with same tabs
    By Djony in forum Qt Programming
    Replies: 20
    Last Post: 24th December 2011, 12:20
  3. stylesheet code for width of a TabBar of a QTabWidget
    By mstegehu in forum Qt Programming
    Replies: 1
    Last Post: 31st May 2011, 12:13
  4. show Tabbar only if there are more than 1 tabs.
    By momesana in forum Qt Programming
    Replies: 2
    Last Post: 23rd September 2007, 20:07
  5. Customize QTabBar or QTabWidget
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 15th February 2006, 08:39

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.