Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close button only for some tabs in Qt

I am using Qt for an assignment I have for college, and I want to use QTabWidget to display a chat window much like Pidgin's. I want to make the "group chat" tab always open and impossible to close and the rest of the "private channel" tabs closable.

QTabWidget's setTabsClosable(bool) is not helping.

Any ideas?

like image 829
Costy Avatar asked Apr 11 '10 08:04

Costy


2 Answers

I found an easier solution, I think. Simply access the relevant close button and resize it.

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

like image 76
etetamar Avatar answered Dec 21 '22 20:12

etetamar


Find the bar (it is private, so use findChild()) and remove the buttons. Documentation claims that close buttons may be placed on left side too.

QTabBar *tabBar = ui->tabWidget->findChild<QTabBar *>();
tabBar->setTabButton(0, QTabBar::RightSide, 0);
tabBar->setTabButton(0, QTabBar::LeftSide, 0);
like image 36
user66960 Avatar answered Dec 21 '22 20:12

user66960