I am trying to catch the hide/show events in a widget which has been placed in a QDockWidget. The problem is that after I tabify the Dockwidget, it doesn't get those notifications anymore when I switch tabs. This behaviour differs from that of an ordinary QTabWidget.

I am using Qt 4.3.0 at the moment and I would like to know if this is wanted behaviour, or if it has been fixed in the 4.4 branch, otherwise I'll file a bug report.

Here is an example to test the behaviour:

Qt Code:
  1. #include <QtGui>
  2.  
  3. class MyLabel : public QLabel
  4. {
  5. public:
  6. MyLabel()
  7. : timesHidden(0)
  8. , timesShown(0)
  9. {
  10. }
  11. void showEvent(QShowEvent*)
  12. {
  13. timesShown++;
  14. QString text;
  15. text.sprintf("Times hidden: %d\nTimes Shown: %d", timesHidden, timesShown);
  16. setText(text);
  17. }
  18. void hideEvent(QHideEvent*)
  19. {
  20. timesHidden++;
  21. }
  22. int timesHidden;
  23. int timesShown;
  24. };
  25.  
  26. int main(int argc, char* argv[])
  27. {
  28. QApplication app(argc, argv);
  29. QMainWindow window;
  30. window.setCentralWidget(new QTextEdit(&window));
  31.  
  32. QList<QDockWidget*> dockWidgets;
  33. for (int i=1;i<=3;i++){
  34. QDockWidget* dock = new QDockWidget(QString::number(i), &window);
  35. dock->setWidget(new MyLabel);
  36. window.addDockWidget(Qt::BottomDockWidgetArea, dock);
  37. dockWidgets << dock;
  38. }
  39. window.tabifyDockWidget(dockWidgets[1], dockWidgets[2]);
  40.  
  41. window.show();
  42. return app.exec();
  43. }
To copy to clipboard, switch view to plain text mode