Weird behavior for ScrollArea with Grid layout after ~195 widgets
-
Hi there!
Sorry for the weird question/noob question, I'm still new to Qt and programming in general!I'm writing a photo gallery similar to Google/Apple photos, with one specific feature I want to implement - continuous scrolling.
The main issue I am currently facing is that after 65 rows (3 media per row -> 195 pictures/mp4s) of Qlabel widgets (with pixmaps attached for images) and custom widget objects for multimedia (MP4s), the layout starts putting widgets atop each other.The error I get in console is: QWindowsWindow::setGeometry: QWindowsWindow::setGeometry: Unable to set geometry 500x500+13+51269 (frame: 500x500+13+51269) on QWidgetWindow/"QLabelClassWindow" on "\.\DISPLAY1". Resulting geometry: 500x500+13+32767 (frame: 500x500+13+32767) margins: 0, 0, 0, 0 minimum size: 400x400 maximum size: 400x400 MINMAXINFO(maxSize=POINT(x=0, y=0), maxpos=POINT(x=0, y=0), maxtrack=POINT(x=500, y=500), mintrack=POINT(x=500, y=500)))
As far as my understanding of error messages go, this makes me think a picture of 500x500 dimensions cannot be put into a 400x400 QLabel, which is weird since I applied the .scaled function to the pixmap, as well as that this error doesn't pop up with <~195 media.
What I also find interesting is that the scroll area continues to expand to accommodate more widgets but it's left empty. As if the grid ended and caused a pile-up while the scroll area expands.
For code, here is my git link, with specific focus on serverFuncs -> serverUserInterface && pySide6VideoWidget.
[End of main issue]
Finally, I know this will be a VERY memory and computation-intensive display (imagine all my images being displayed ~200,000), so I was thinking of hiding widgets that cannot be seen by the user. E.g. as one scrolls down, the images that move out of view at the top .hide() and the ones below .show() - I haven't dug deep into the documentation to see if there is a "user-POV" function, but is this even possible/a good idea. I'm also thinking of using multiprocessing to allow for multiple widgets to be prepared to add to an area (I'm thinking of having processes create the objects and put them into a queue which then gets added to the area via the relative main process - this assuming the creation of a widget is more computationally intensive than adding it to the GUI).
Sorry for the long post, and thank you for any and all help. I greatly appreciate it!
Niccolo v.
-
Hi and welcome to devnet,
You are using the wrong tool for your use case.
You should use the model view paradigm and not create that many widgets. For your images and videos you should create thumbnails that will allow to show smaller versions of your media without filling your RAM.
-
@SGaist Thank you for the reply and help!
I changed my formatting into a QTableWidget and noticed a decent performance improvement, but I haven't found a way to render a video in an item, so I'm still using widgets for that - which leads to issues.
I looked through the forum and found this post , say I do want to play videos in the table without a dedicated media player beside it, what would be your recommendation?
Additionally, for my own curiosity, what causes a large number of widgets to cause errors? Is it a limitation of Python, Qt, or hardware?
Thank you!
Niccolo v. -
@Niccolo-v showing the videos would require a custom delegate.
As for the issue with a high count of widget, I can't comment without a reproducer.