Hi,

some code for you to discuss, if you like.
I wrote a class, that detaches children of a QTabWidget and then also putting it back to the TabWidget. It works in the following way:
If you right click on a child of a QTabWidget, you get a custom menu, with only one entry: "Detach". If you click on it, the Widget becomes a Window and the tab is removed. If you now right click on that window, another custom menu shows up with a "Attach" entry. Clicking on that, the wdiget becomes a child of the QTabWidget again, at the old position, with the same TabText:
Qt Code:
  1. class WidgetDetacher : public QObject {
  2. Q_OBJECT
  3. public:
  4. WidgetDetacher(QTabWidget* parent, QWidget* subject);
  5. public slots:
  6. void detachWidget();
  7. void attachWidget();
  8. void showContextMenu(const QPoint &pos);
  9. private:
  10. QWidget* _subject;
  11. QTabWidget* _parentTabWidget;
  12. QString _tabLabel;
  13. int _tabPos;
  14. };
  15.  
  16. WidgetDetacher::WidgetDetacher(QTabWidget* parent, QWidget* subject) :
  17. QObject(parent) {
  18. _parentTabWidget = parent;
  19. _subject = subject;
  20. if (_subject != 0) {
  21. _subject->setContextMenuPolicy(Qt::CustomContextMenu);
  22. connect(_subject, SIGNAL(customContextMenuRequested(const QPoint &)),
  23. this, SLOT(showContextMenu(const QPoint &)));
  24. }
  25. }
  26.  
  27. void WidgetDetacher::detachWidget() {
  28. if (_subject != 0) {
  29. if (_subject->parentWidget() != 0) {
  30. _tabPos = _parentTabWidget->currentIndex();
  31. _tabLabel = _parentTabWidget->tabText(_tabPos);
  32. _parentTabWidget->removeTab(_tabPos);
  33. _subject->setParent(0);
  34. _subject->show();
  35. }
  36. }
  37. }
  38.  
  39. void WidgetDetacher::attachWidget() {
  40. if (_subject != 0 && _subject->parentWidget() == 0) {
  41. disconnect(_parentTabWidget, SIGNAL(destroyed(QObject*)), _subject, SLOT(close()));
  42. _parentTabWidget->insertTab(_tabPos, _subject, _tabLabel);
  43. _parentTabWidget->setCurrentIndex(_tabPos);
  44. }
  45.  
  46. }
  47.  
  48. void WidgetDetacher::showContextMenu(const QPoint &pos) {
  49. QMenu menu;
  50. if (_subject != 0) {
  51. if (_subject->parentWidget() != 0) {
  52. menu.addAction(tr("Detach"), this, SLOT(detachWidget()));
  53. } else {
  54. menu.addAction(tr("Attach"), this, SLOT(attachWidget()));
  55. }
  56. menu.exec(((QWidget*) _subject)->mapToGlobal(pos));
  57. }
  58. }
To copy to clipboard, switch view to plain text mode 

There are currently two drawbacks:
If you have your own cusom menu in the childwidget, it gets messy.
If you close the Widget containing the TabWidget, the former child widget wont be closed, if detached. And because I dont want the user to close the Tab, so I disabled the clos button on the child widget.
I am still working on that.
It would be cool, if you could drag a Tab outside of the TabWidget, and if that would make the child widget become a window. But until i figured out, how to do that (if its even possible), it will stay this way.