PDA

View Full Version : Parentwidget doubt. Create new widgets with parent or not ?



tonnot
9th February 2012, 12:42
In case I dont need to do any particular thing with widgets, it is neccesary to create them always with parentwidget parameter?

Another question, I have a custom widget, I create a Qframe, a layout for it, and 3 widgets (added to the layout)
If a Qframe is the parent of a Qlayout and inside it I have the 3 widgets.... At the time of delete the whole custom widget have I to delete every widget or in case there are right parentwidget for everyone, is it right to delete only the main parentwidget ? (if not, then I dont know the meaning of givin parents... )
Thanks.

KillGabio
9th February 2012, 14:58
I guess not, that`s why by default if you dont pass a parent when creating an object, parent var is set to NULL.

The most common problem that arouses when you DONT give a parent is that the user can, for example, click the parent Widget that is open. For example...your app has a Widget that export`s data and while the data is exporting nothing can be done/clicked because can cause crash of the app. For that purpose you have, for example, a Dialog with a progress bar that tell you how much time is left to finish the operation. If you dont give the Widget as a parent for the dialog then the user can change things of the Widget running and the information is going to be inconsistent. I know there are other ways of preventing that to happen but hope I could give you a hand.

tonnot
13th February 2012, 08:28
Thanks K. However I still have a question about deleting.

FelixB
13th February 2012, 09:22
Another question, I have a custom widget, I create a Qframe, a layout for it, and 3 widgets (added to the layout)
If a Qframe is the parent of a Qlayout and inside it I have the 3 widgets.... At the time of delete the whole custom widget have I to delete every widget or in case there are right parentwidget for everyone, is it right to delete only the main parentwidget ? (if not, then I dont know the meaning of givin parents... )

As already mentioned in the other thread, you don't have to delete widgets manually that are arranged in a layout. when you delete your custom widget, the layout gets deleted. Deleting the layout deletes all contained widgets automatically.

Felix