QTabWidget: close tab button not working

Tab picture Tab · Oct 3, 2013 · Viewed 13.9k times · Source

I have set ui->tabWidget->setTabsClosable(true); but QTabwidget only showing a cross on each tab that is not closing tab on click on this button. What else I have to do to make tabs closable? I tried to connect any slot (which would be proper for this work) of close to signal tabCloseRequested(int) but couldn't find any such slot in tabwidget. Please suggest the right way.

Answer

Pavel Strakhov picture Pavel Strakhov · Oct 3, 2013

Create a slot e.g. closeMyTab(int) and connect the tab widget's tabCloseRequested(int) signal to this slot. In this slot call tab widget's removeTab method with the index received from the signal.

See this answer for more details.