Layout not "updating" when removing all widgets inside it
So I have a Scrollarea with a
There's a button that will add a widget to the
There's also a button that will remove all the widgets:
for i in reversed(range(self.layout.count())): widgetToRemove = self.layout.itemAt(i).widget() # remove it from the layout list self.layout.removeWidget(widgetToRemove) # remove it from the gui widgetToRemove.setParent(None)
But after clicking the remove all button then the widgets are removed BUT they still "stay" and after you add a new widget to the layout the other ones disappear and the new one is added.
Before pressing the "Eemalda koik" button which will remove all widgets:
Screenshot 2019-06-07 at 14.52.19
After pressing the Eemalda koik button:
Screenshot 2019-06-07 at 14.53.13
And only after refocusing the widgets disappear (note, after pressing the Eemalda koik button, pressing the red crosses doesn't work because the widgets aren't there but I can still see them)
You can try to call
What flavour of python bindings are you using ?
Which version is it ?
Okay as denoted by someone else on this site a mini-program that works using your example would be very helpful along with knowing what version of python and pyqt you are using -- (I assume python 3.7 with pyqt5 unless others denoted)
As for the issue, this sounds like a standard GUI refresh issue which actually is an issue with most GUI software. You basically have to force a refresh of all the windows (or layout/widgets) involved. There are a few suggestions on how to do this if you google "pyqt5 how to force a view refresh" I am sure one of those will answer your question. If its still an issue after you institute a refresher do let us know.
For instance here is one that might answer your question
pyqt5 how to force a view refresh
This only seems to be a problem for OSX, since when I tested this on windows 7 then it worked fine.
Can you anyway share the version of PyQt/PySide2 you are using ?
@Fuchsiaff not sure why you made that statement as it does not make much sense to me so if I am wrong with my interpretation I will apologies upfront... -- ultimately everything within pyqt is an object and any container object involved in displaying something be it a widget, a layout, a window or any other container object -- may have this refresh issue as it is not an uncommon issue with GUI software in general -- so basically you making a change that should affect what you see and you are not seeing it -- so the question is -- (Q) Is the change actually occurring behind the scenes .. if yes then it is definitely just a refresh of the front-side (what you see) that is the issue ... if no then you have something failing on the back-side
Regardless as has been requested twice denoting what version of Python and pyqt (or pyside as they are not the same thing) you are using might help us have a better idea of why this might be happening so far we (who are just trying to help you) are running on pure assumptions of what you are using which means we cannot really help you as effectively.
When you unfocus from the app and then later refocus then the changes have happened, calling activate or any of the functions the layout calls automatically doesn't do the trick
Using PyQt5 5.12.1
Denni last edited by
Okay first are we to assume that you are using some version of Python 3.7 or are you using an earlier version of Python?
Next the question still stands when you make the presumed change does the behind-the-gui reflect those changes -- use a command line print or log to a file with some information that ascertains this -- and if yes -- then yes it is a rendering issue and not some delayed underlying event handling thing
If it gets ascertain as being purely front-side-gui rendering then its just a matter of figure out what event exactly needs to be triggered in order to trigger what you want to have happen --- the on activate (as you state) appears to do this which means that there is something within pyqt5 that will do this one just has to drill down and find that something. However the snippet that you share does not allow me to run what you are running to try and help you with that issue. I am not asking you to post your entire project just a small version that encapsulates what you are doing where you are experiencing the issue -- that repeats the issue so that we can see it and play with it to help you to determine how it can be fixed to help you.
Again we are just humble programmers we like to think we are all powerful beings but we are actually just cast aways on a beach fairly amazed and delighted when we make a fire with some sticks
This was only a problem on MacOS and after rebooting my system it started working like it should've. Updating the GUI without having to refocus the entire application.
I don't remember if I mentioned it but I tried the same program on Windows 7 and that didn't have such problem.
Both the python version and the pyqt versions were the same.
I would also like to apologise for not providing enough information!
@Fuchsiaff okay it sounds like you resolved your issue is that correct? (if yes then you should probably mark this thread as resolved yes/no?) (either you did this after my post or I missed it coming if the latter my apologies)
Regardless I did not understand this (for your future reference) "Both the python version and the pyqt versions were the same" as the most current version of python is 3.7.? and the most current version of Qt is 5.? and the last time I looked 3.7.? does not equal 5.? :)
Lastly I know I for one appreciate the apology and I am sure others did as well ;) kudos to you for that
I meant that on both of the machines the python version was the same (3.7) and PyQt5 version was the same (5.12.1)