Registered Member
|
Hi there,
this thing is bugging me for a while now... basically it is as simple as that: i have a couple of lables and textedit-elements in a layout which i want to be able to remove - to reset the layout and fill it in another way on user action. The layout classes offer two functions for that, removeItem() and removeAt(). The first method takes a variable referencing the element, the second an index. However, both possibilities end up in having the elements rather detached, but are still visible. So, has anyone an idea how i can really and finally remove such an element? Below is a minimalistic, but working code snippet that demonstrates the behaviour. A layout contains a PushButton as well as a Label. When you click the PushButton, the Label gets "removed" (as in detached, but not destroyed) from the layout, so that the PushButton gets all the space (ok), but the Label is still visible and on top of it.
|
Administrator
|
You need to destroy the Label object somehow, not sure how one does that in javascript. You could try to call deleteLater() on it however, which is a Qt C++ call. It may not be available in the Javascript API though.
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
Registered Member
|
Exactly!
At least it is not documented, but may be hidden or so... i will have a look this evening, thanks. |
Registered Member
|
It seems like I found a solution. It looks kind of dirty, though, but seem to work. Full story:
I printed all members of the plasmoid object and indeed I found the methode deleteLater(). Using it by passing the element object did not have an visible effect, though – but an inner one, as i can run this line only once. I also tried it in combination with plasmoid.update() with the same results. So I also gave out the members of the Label object and found the method close(). So i tried this and - woohoo - the Label vanished. However, the variable still has had the object reference. So I added "delete innocentLabel" and this was done, too. → I hope this is a solution that also sets free the occupied memory. It feels dirty anyway. The full code snippet which hopefully really and finally deletes the object:
@bcooksley: Thanks for the hint and for bringing me on the right path Update: The delete line only deletes the reference to the object. Job of the garbage collection is to clear the object, if it is unreferenced. Is it possible that some internal stuff keeps it alive until the plasmoid is removed or plasma quitted? |
Administrator
|
Note that you shouldn't need to close it or otherwise delete it, as deleteLater() should ensure it is destroyed on the next pass of the event loop. It is probable that Plasma does something to keep these objects alive however.
KDE Sysadmin
[img]content/bcooksley_sig.png[/img] |
Registered Member
|
Okay, PEBCAK.
Instead of calling plasmoid.deleteLater(thing) the correct usage is to call the method deleteLater() of the object itself. Must have overlooked it, when i studied the object's method Thanks for your help and insisting on deleteLater |
Registered users: Bing [Bot], Evergrowing, Google [Bot], rockscient