[Qt-interest] Problem with adding/removing/adding elements in a QVBoxLayout

Juan Pablo Crossley crossleyjuan at gmail.com
Fri May 15 14:29:46 CEST 2009


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090515/fac9b506/attachment.html 


More information about the Qt-interest-old mailing list