Removing one Tab in a QTabWidget
-
Hi everyone!
I have created a QTabWidget and I set the tabsClosable to true and I have also connected it to a slot like this:
@
connect(onglets,SIGNAL(tabCloseRequested(int)),this,SLOT(onfermerOnglet(int)));
@
Next, I implemented the onfermerOnglet(int i) slot like this:
@
void MainWindow::onfermerOnglet(int index){
onglets->removeTab(onglets->currentIndex());
}
@where onglets is a tabwidget.
When I execute my code, create some widgets (maybe 5) and I remove one (maybe the index ->2) it also removes all tab index above (it removes index 2, index 3 and index 4) instead of just removing tab index 2. Can someone help me?
-
i'm not sure if that will be already a solution to your problem, but is there any reason why not using the index supplied by the signal?
@
void MainWindow::onfermerOnglet(int index)
{
onglets->removeTab(index);
}
@ -
[quote author="irobot" date="1367146830"]Problem solved[/quote]
Please share the solution so you it may help others...
-
I might want to add that you also have to delete the content inside the tab. Deleting the tab itself will not delete the page. Alternatively, you can delete the page itself, which will in turn delete the tab.
@void MainWindow::onfermerOnglet(int index)
{
onglets->widget(index)->deleteLater();
}
@ -
Hi raven-worx
I forgot what exactly the problem was (sorry) but I think I have to tell you a little about the code. I have a MainWindow which contains a QTabWidget named onglets. I created a class named Widget that I display as tabs in onglets and I have a slot that creates tabs named createTab() where we create a Widget and add it to the QTabWidget. The error I made is to put the slot onfermerOnglet() in the createTab() and I remark that when I close maybe the last tab, it launches a loop and the index (onfermerOnglet() slot parameter) decreases. I don't know if I am really clear because I am struggling with my English.Why not using the index?You are right and I already correct it. About tab's content, I didn't know that so thanks again.
Best Regards,
iRobot