Qt 4.5 以降。を呼び出すだけの場合、閉じるボタンは表示setTabsClosable(true)
さQTabWidget
れますが、アクションにバインドされません。
ボタンに何かをさせたい場合は、tabCloseRequested(int) シグナルを独自のスロットの 1 つに接続する必要があります。
MainWindow::MainWindow()
m_tabs = new QTabWidget();
m_tabs->setTabsClosable(true);
connect(m_tabs, SIGNAL(tabCloseRequested(int)), this, SLOT(closeTab(int)));
void MainWindow::closeTab(const int& index)
{
if (index == -1) {
return;
}
QWidget* tabItem = m_tabs->widget(index);
// Removes the tab at position index from this stack of widgets.
// The page widget itself is not deleted.
m_tabs->removeTab(index);
delete(tabItem);
tabItem = nullptr;
}