[Qt-interest] Problem with adding/removing/adding elements in aQVBoxLayout
Andreas Diehl
Andreas_Diehl at abs.org
Fri May 15 14:55:59 CEST 2009
Hi Pablo.
I remember having the same problem though with QtJambi. There my
solution - which worked really fine - was to call the dispose()-method
of the removed widget like:
myLayout.removeWidget( widgetToRemove );
widgetToRemove.dispose();
I didn't find that method in standard Qt but you can try
QWidget::deleteLater() or QWidget::destroy(bool, bool) or simply delete
it. The problem is, the widgets are gone after that, thus re-adding
isn't possible :I
I'd begin with deleteLater() :)
I hope it solves your problem... because I'll soon have the same to do
;)
Regards,
Andreas
________________________________
Von: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] Im Auftrag von Juan Pablo
Crossley
Gesendet: Freitag, 15. Mai 2009 14:30
An: qt-interest at trolltech.com
Betreff: [Qt-interest] Problem with adding/removing/adding
elements in aQVBoxLayout
Hi, I'm trying to add and remove some elements in a QVBoxLayout
in order to recreate the contents but it is not redrawing nicely, the
result is a screen with the old items and the new ones, although the
items were removed correctly. I've been working in this for two days and
can't figure out what is wrong, can't anyone point me in the right
direction?
Here's the code I'm using to remove the current items and
recreate them:
QVBoxLayout* lay = (QVBoxLayout*)layout();
for (int x = 0; x < m_size; x++) {
TaskElement* element = currentElements[x];
lay->removeWidget(element);
}
(here's a code to clean the currentElements array)
and later I do:
for (...)
lay->addWidget(..);
with the new widgets to display, but the result is a messy
screen with the old widgets and the new ones, if I change the size of
the window the result is the expected one (only the new widgets are
drawn), but as soon as I restore the window size the mess shows up
again. I also tried removing the elements using:
QLayoutItem* item;
while ((item = lay->takeAt(0)) != 0) {
delete item;
}
also tried to call the update method for the layout, and the
update() for the parentWidget and neither of them worked. (I also tried
the activate, invalidate methods too).
any hint? thx in advice for your help
--
Cross
--
Mit freundlichen Gru?en
Andreas Diehl
-------------------------- ABS -------------------------
ABS Systemberatung OHG Tel: +49 (0)7053/9290-03
Hauffstr. 9 Fax: +49 (0)7053/9290-
D-75385 Bad Teinach-Zavelstein http://www.abs.org
Registergericht Calw HRA 1031
[mailto:Andreas_Diehl at abs.org]
----- Loesungen fuer den Maschinen- und Anlagenbau -----
More information about the Qt-interest-old
mailing list