[Interest] What is the correct way of removing UI elements with code ?

Nikos Chantziaras realnc at gmail.com
Wed Oct 10 18:27:34 CEST 2012


On 10/10/12 18:05, Patryk Małek wrote:
> I have just encountered a problem, where I do not need a certain UI
> element e.g. /QPushButton/ and I would like to remove it but since I
> have connected it with several slots (e.g. /clicked(), released()/ etc.
> ) I now have several references of this button in my code.
>
> How can I remove all of this efficiently ? Do I have to remove it all
> manually ?

When you delete a widget, all its connections are automatically 
canceled.  So you can simply delete it.  If you still need it for later, 
then follow Bo Thorsen's advice; although the disconnect() call is not 
really necessary if the widget only sends signals and doesn't receive 
any, since when you hide the button, it cannot be interacted with and 
thus it will emit no signals.  You can simply hide() it without doing a 
disconnect().




More information about the Interest mailing list