PDA

View Full Version : Problem updating a layout



Wach
14th August 2010, 16:23
Hi. I really hope that this is the right section to place my question..:P
Well the problem is that i have a layout with a customized widget that renders a graph in openGL.. but each time i remove the widget from the layout to add a new one, with a different graph, the previous one stays there...( this makes the screen show sometimes the older graph and sometimes the new when i press the mouse in the widget area).
I've already made a lot of updates and destroys on the previous one but the image really like where it is. The only way i can make the previous to stop rendering is to resize the whole application.. after that the previous stops showing..
i don't have a clue of what to do... does anyone know how to solve this
thanks in advance

tobi
14th August 2010, 17:01
Maybe you should post some code. At least the code where you add and remove the widgets to the layout.
Otherwise it's difficult to help here.

Wach
14th August 2010, 21:35
the initial code is this:

self.imageLabel = QLabel()
self.imageLabel.setMinimumSize(588,588)
self.imageLabel.setAlignment(Qt.AlignCenter)
self.imageLabel.setContextMenuPolicy(Qt.ActionsCon textMenu)
self.imageLabel.setPixmap(QPixmap.fromImage(QImage ("images/img1.jpg")))
self.imageLabel.setObjectName("imageLabel")

self.centralLayout = QHBoxLayout()
self.centralLayout.addWidget(self.imageLabel)

after this to change the widget or replace by other this is what i do

self.centralLayout.removeWidget(self.imageLabel)
...
self.centralLayout.update()
self.imageLabel = GLWidget(self.graph, self.leftGL, self.rightGL, self.bottomGL, self.topGL, self.colors, self)
...
self.centralLayout.addWidget(self.imageLabel)

thanks

Urthas
16th August 2010, 21:13
So you removeWidget()...what do you do with the removed widget?

Wach
16th August 2010, 23:14
hmmm nothing... i just remove it and replace it by other... should i be doing something else?

Urthas
16th August 2010, 23:50
Yes. You should delete it, using the delete() or deleteLater() function as appropriate.

Wach
17th August 2010, 00:21
delete? but the qwidget class doesn't have any delete... how do i do that?

Zlatomir
17th August 2010, 00:38
Actually it has the deleteLater(); (http://doc.qt.nokia.com/4.6/qobject.html#deleteLater) member slot (inherited from QObject)

LE: Back to original problem, have you tried to call repaint() (http://doc.qt.nokia.com/4.6/qwidget.html#repaint) (see also update() (http://doc.qt.nokia.com/4.6/qwidget.html#update)) after you change the central widget (or maybe another idea is to use the same widget and update it as necessary)