Results 1 to 3 of 3

Thread: ParentWidget gives me alwasy the mainwindow widget ....

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default ParentWidget gives me alwasy the mainwindow widget ....

    Hello everybody:
    I have a few widgets placed into different containers (Qframes and Qwidgets). I have them at mainwindow level and a Qdialog level
    In example :
    Mainwindow->centralwidget->frame1->frame2->my_widget1;
    Dialog->frame1->frame2->my_widget2;
    Ok I have this code to find the top owner:

    Qt Code:
    1. QWidget * W_qtutil::w_tell_me_the_topwidget(QWidget *widget)
    2. {
    3. if (widget->parentWidget()!=0)
    4. { QWidget * top_p = widget;
    5. while (top_p->parentWidget()!=0)
    6. { top_p = top_p->parentWidget(); } // HERE
    7. return top_p;
    8. }
    9. else
    10. {
    11. return widget;
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 
    (Still the code is not finished, I have to control when I reach a Window widget).

    Ok, I have a problem, at the line marked by 'HERE' , top_p = top_p->parentWidget(); at the first excecution I have the "Ui_main" of my application, regardless of the original mainwindow or dialog where I have the widget.

    That is , I 'd have to get:
    frame2, frame1, centralwidget,mainwindow for my_widget1;
    and
    frame2. frame1, dialog for my_widget2;

    But I always get Ui_main at the first time.
    Any idea ? Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: ParentWidget gives me alwasy the mainwindow widget ....

    Hmm... what's wrong with QWidget::window()?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. The following user says thank you to wysota for this useful post:

    tonnot (7th March 2012)

  4. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: ParentWidget gives me alwasy the mainwindow widget ....

    Ups. You're right.

Similar Threads

  1. Replies: 3
    Last Post: 13th February 2012, 08:22
  2. Replies: 2
    Last Post: 25th November 2011, 00:47
  3. Replies: 0
    Last Post: 6th November 2011, 09:22
  4. Replies: 10
    Last Post: 29th May 2010, 18:42
  5. QwtPlot widget in MainWindow
    By sabeesh in forum Qt Programming
    Replies: 1
    Last Post: 25th July 2007, 11:48

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
  •  
Qt is a trademark of The Qt Company.