Hi All,

I have an application where in which I have a main widget which acts as parent for all the child widgets that are created on the fly.
I have been trying to control the window managment in my application such that child widgets are inserted in the order what I expect.

Qt Code:
  1. QWidget *pMainWid = new QWidget(NULL); // Independent Widget
  2.  
  3. QWidget* getQtWidget(QWidget *p_Parent)
  4. {
  5. // MyWidget is the customized widget from the QWidget
  6. MyWidget *pchildWidget = new MyWidget(p_Parent);
  7. // customize the widget as required
  8. // .....
  9. return pChildWidget;
  10. }
  11.  
  12. void insert(int position)
  13. {
  14. QList<MyWidget *> winList = findDirectChild<MyWidget *>(pMain);
  15. MyWidget *underWhichWin = NULL;
  16.  
  17. QWidget *pChildWidget = getQtWidget(m_pQtParentWidget);
  18.  
  19. if(position > 0) {
  20. underWhichWin = winList.at(position - 1);
  21. pChildWidget->stackUnder(underWhichWin);
  22. }
  23. //pChildWidget->setVisible(true); // <Why do we need to set Visibility of the Child Widget to True?>
  24.  
  25. pMain->show();
  26.  
  27. // Update the state of all windows
  28. recomputeWidgetState();
  29. }
  30.  
  31. void recomputeWidgetState()
  32. {
  33. WIDGET_STATE newState;
  34.  
  35. QList<MyWidget *> winList = findDirectChild<MyWidget *>(pMain);
  36.  
  37. for(int current = 0; current < winList.count(); ++current)
  38. {
  39. MyWidget *wdgt = winList.at(current);
  40. std::cout << "\tVisible? " << wdgt->isVisible() << std::endl;
  41. QRegion wdgtVisRegn = wdgt->visibleRegion();
  42. QRect wdgtVisRegnBundRect = wdgtVisRegn.boundingRect();
  43. QRect wdgtRect = wdgt->rect();
  44.  
  45. if(wdgtVisRegn.isEmpty()) {
  46. newState = WIDGET_OBSCURED;
  47. } else {
  48. if( (wdgtVisRegnBundRect == wdgtRect) && (1 == wdgtVisRegn.rects().count()) ) {
  49. newState = WIDGET_VISIBLE;
  50. } else {
  51. newState = WIDGET_PARTIAL;
  52. }
  53. }
  54. wdgt->setCurState(newState);
  55. } // end of for loop
  56. }
To copy to clipboard, switch view to plain text mode 

Note: I am doing all insertion operation after the event loop starts (inside the Qt Event Loop) [ It is the project requirement]
Problem: During recomputing the Widget State I am observing folowing things:
a. If "pChildWidget->setVisible(true);" is enabled I will get the proper z-order what I expected and all child widgets are shown
b. If I exclude the "pChildWidget->setVisible(true);" statement Child widgets are not show and I will not be getting the proper z-order what I expect.

Query: As per my knowledge if we say show() on parnet widget it shows all its children. But in the above case, if we set the visibility of the child to true explicitly
the application displays the child widget otherwise not. What is wrong in my impmentation? Why do we need to set the visibility explicitly?

Please clarify.

Thanking You
SRaju