Results 1 to 5 of 5

Thread: show() on parent widget doesn't show the child widgets

  1. #1
    Join Date
    Oct 2013
    Location
    Everett WA USA
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default show() on parent widget doesn't show the child widgets

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: show() on parent widget doesn't show the child widgets

    You are saying that all insertions happen after the event loop has started. So the main window has already processed its show event.
    Or are you creating a hidden window and calling show() when you have done all insertions?

    Btw, it is very uncommon to handle placement and z-order of widgets manually. What do you want to achieve?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2013
    Location
    Everett WA USA
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: show() on parent widget doesn't show the child widgets

    Thanks for the response.

    We are not explicitly creating hidden windows. Just normal Widget Creation. Are these widgets hidden if we create using new operator ?

    We have an old application and they window management has been written using list in C++. I am trying to port that application to Qt such that Qt can take over the window management. So, the order in which the windows are managed in old code should be done in Qt as well.

    Is there a way to inform the Qt to process the show() event once after the event loop started.? Or Calling show() does is sufficient?

    Please advice

    Regards
    SRaju

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: show() on parent widget doesn't show the child widgets

    Quote Originally Posted by sraju View Post
    We are not explicitly creating hidden windows. Just normal Widget Creation. Are these widgets hidden if we create using new operator ?
    I meant the main window. Do you call show() somewhere in main() before starting the event loop or are you calling show() after creating the children?

    By default all widgets are not yet visible and need to be shown. Children are shown with their parent unless they have been explicitly hidden.

    So it depends if your main window has already been shown at the time of child creation. If it has, then the children will remain hidden (their parent didn't get shown after their creation).

    Quote Originally Posted by sraju View Post
    We have an old application and they window management has been written using list in C++. I am trying to port that application to Qt such that Qt can take over the window management. So, the order in which the windows are managed in old code should be done in Qt as well.
    Is this an MDI application? Are you using QMdiArea?

    Quote Originally Posted by sraju View Post
    Is there a way to inform the Qt to process the show() event once after the event loop started.? Or Calling show() does is sufficient?
    Calling show() is sufficient, it results in an event being sent to the respective widget, so it needs a running event loop to get processed.

    Cheers,
    _

  5. #5
    Join Date
    Oct 2013
    Location
    Everett WA USA
    Posts
    12
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: show() on parent widget doesn't show the child widgets

    I meant the main window. Do you call show() somewhere in main() before starting the event loop or are you calling show() after creating the children?
    No. I will not be calling the show() I will call the show() on Main Widget After creating the child widgets and it is after the event loop starts.

    By default all widgets are not yet visible and need to be shown. Children are shown with their parent unless they have been explicitly hidden.

    So it depends if your main window has already been shown at the time of child creation. If it has, then the children will remain hidden (their parent didn't get shown after their creation).
    It has answered my query and concludes that each child widgets needs to be shown when they are added after the event loop starts.
    Is this an MDI application? Are you using QMdiArea?
    No, it's not designed using QMdiArea. We are considering each QWidget as a Window and it is serving our purpose.

    Thanks for the support.


    Regards
    SRaju

Similar Threads

  1. Replies: 4
    Last Post: 8th January 2013, 00:43
  2. show widget over other widgets
    By maston in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2010, 10:31
  3. Custom Widget doesn t show.
    By Frej in forum Qt Tools
    Replies: 12
    Last Post: 11th March 2010, 11:48
  4. QMainWindow and custom widget doesn't show
    By Peppy in forum Qt Programming
    Replies: 9
    Last Post: 26th December 2009, 16:09
  5. Corner widget in QTabWidget doesn't show up
    By ePharaoh in forum Qt Programming
    Replies: 2
    Last Post: 6th April 2006, 18:02

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.