PDA

View Full Version : How to get the base parent Widget



vaibhav
15th February 2011, 08:35
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.

Lykurg
15th February 2011, 08:37
What's about
pushButton->parentWidget()->parentWidget();? Also check for null pointers!

vaibhav
15th February 2011, 08:53
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...

Lykurg
15th February 2011, 09:08
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?

nightghost
15th February 2011, 09:20
I did't try it, but QWidget::window sounds like you could reach the QDialog with it.

vaibhav
15th February 2011, 09:30
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.

nightghost
15th February 2011, 09:34
and


connect(the_button, SIGNAL(triggered()), the_dialog, SLOT(accept())

is not possible?

vaibhav
15th February 2011, 09:58
Button's parent is not necessarily the QDialog type it could be QWidget or QMainwindow also.So above code wont work.

nightghost
15th February 2011, 12:27
Please show us the code.