Results 1 to 9 of 9

Thread: How to get the base parent Widget

  1. #1
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default How to get the base parent Widget

    Hi,
    I have QDialog as Base parent.And my direct child for that dialog is QPushbutton *pushButton.
    I could retrieve the Qdialog through pushButton->parentWidget().

    Now my QPushButton is not the Direct Child of QDialog.It is Child of QScrollArea which in turn is child of QDialog.
    child child
    QDialog->QScrollArea->QPushButton.


    How can i get the QDialog through pushButton.
    pushButton->parentWidget() in this case will return QScrollArea.

    Any help would be appreciated.

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to get the base parent Widget

    What's about
    Qt Code:
    1. pushButton->parentWidget()->parentWidget();
    To copy to clipboard, switch view to plain text mode 
    ? Also check for null pointers!

  3. #3
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to get the base parent Widget

    But how long i have to check for parentwidget() coz this indirect child relation can extend for long .Isn't there a better way to get the QDailog at first instance only.

    Or some optimized code to do so.?
    Thanks...

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: How to get the base parent Widget

    I don't know a better way. You can use a loop and check if it is a QDialog and then stop. Why do you need that pointer anyway?

  5. #5
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the base parent Widget

    I did't try it, but QWidget::window sounds like you could reach the QDialog with it.

  6. #6
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to get the base parent Widget

    Quote Originally Posted by Lykurg View Post
    I don't know a better way. You can use a loop and check if it is a QDialog and then stop. Why do you need that pointer anyway?
    I have a requirement where in i want to close the dialog from pushbutton which could be a direct child or indirect child of dialog.

  7. #7
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the base parent Widget

    and
    Qt Code:
    1. connect(the_button, SIGNAL(triggered()), the_dialog, SLOT(accept())
    To copy to clipboard, switch view to plain text mode 
    is not possible?

  8. #8
    Join Date
    Mar 2009
    Location
    delhi India
    Posts
    56
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: How to get the base parent Widget

    Button's parent is not necessarily the QDialog type it could be QWidget or QMainwindow also.So above code wont work.

  9. #9
    Join Date
    Jan 2009
    Location
    Germany
    Posts
    131
    Thanks
    11
    Thanked 16 Times in 16 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: How to get the base parent Widget

    Please show us the code.

Similar Threads

  1. Replies: 7
    Last Post: 14th January 2010, 08:47
  2. Replies: 4
    Last Post: 3rd October 2009, 08:19
  3. How to move child widget with parent widget?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 15:23
  4. let parent widget grow with child widget?
    By BeS in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2009, 11:17
  5. MVC - Abstract Widget Base Class - setupUI
    By SenSej in forum Newbie
    Replies: 0
    Last Post: 13th October 2008, 10:44

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.