PDA

View Full Version : Disable close button from QTabWidget



migel
20th September 2011, 11:55
How to I remove close button from individual tab ?

Found that but it works only for QTabBar I need that for QTabWidget which seems to not have this option there.

http://www.qtcentre.org/threads/19459-Disable-close-button-on-QTabWidget-QTabBar

pkj
20th September 2011, 15:10
QTabWidget::setTabsClosable()

wysota
20th September 2011, 15:23
Subclass QTabWidget, use QTabBar::tabButton() to access the button from the tab you want to modify and call hide() on it. Alternatively you can hack into the tabbar from an existing tab widget, like so:

class HackedTabWidget {
friend class SomeClass;
};

void SomeClass::someMethod() {
// ...

QTabWidget *tw = ...
HackedTabWidget *htw = (HackedTabWidget*)tw;
QTabBar *tb = htw->tabBar();
tb->tabButton(0, QTabBar::RightSide)->hide();
}

If you don't feel comfortable with hacking into the tabbar, use inheritance instead.