My Application has a QTabWidget as the central widget. I want to implement dock/undock functionality for its tabs. Each tab has a button and a local variable to save its state (dock or undock).

Qt Code:
  1. ....
  2. bool isDocked = true;
  3. ....
To copy to clipboard, switch view to plain text mode 
inside button click event

Qt Code:
  1. if (isDocked)
  2. {
  3. ....
  4. removePage(tab);
  5. tab->reparent(0, QPoint(0,0), true);
  6. isDocked = false;
  7. }
  8. else
  9. {
  10. ....
  11. addTab(tab, name);
  12. isDocked = true;
  13. }
To copy to clipboard, switch view to plain text mode 
This works fine. My problem is the close event. If the tab is Undocked, it appears as a top level widget(with min/max/close buttons). If the user clicked the close button tab should be docked. I have reimplemented tab's closeEvent to get this functionality. closeEvent implementation is same as the button clicked implementation. but it works first time only. after that if i press the close button it does nothing. What can be the problem ? I am using Qt 3. thanks.