[Interest] dynamic widget creation in QScrollArea

Bo Thorsen bo at vikingsoft.eu
Thu Aug 4 10:36:53 CEST 2016


Den 04-08-2016 kl. 10:05 skrev Frank Rueter | OHUfx:
> I am playing with the idea of writing a custom widget based on
> QScrollArea, where widgets are created as the user scrolls.
> I'm just hoping to bounce the general idea of you guys here to see if
> I'm heading in the right direction:
>
> I have a heap of custom widgets, potentially thousands, depending on the
> contents of a database.
> I'd like to show them in a grid that fits as many widgets horizontally
> as will fit in the current window size (dynamic).
> I would also like smooth vertical scrolling.
>
> If I create a single parent widget with a grid layout that creates all
> widgets on start up, it takes ages.
> So I'm thinking if I use the child widgets' visibleRegion() to find the
> ones currently visible in the scroll area, then figure out the indexes
> of the widgets in the rows above and below to create them dynamically,
> that should speed up the startup and still provide smooth scrolling.
>
> Obviously I'd have to manually scale the scroll area based on the
> maximum amount of widgets and the parent widget's width to get an
> indicative scrollbar.
> Not sure how tricky that will be.
>
> Does that sound crazy or doable?
>
> Basically I am trying to re-create the behavior of a QListView in icon
> mode. I tried using QListView with delegates, but couldn't get the
> delegates to provide the kind of complexity I need for the child widgets
> which I have already written (which are basically mini movie players
> that can be drag&dropped and have playback all at once on demand).
>
> Any thoughts on this before I dive into this little experiment?

I don't think that sounds unreasonable. If I were you, I would try very 
hard to stay with QListView instead, but other than that it doesn't 
sound hard to do. Time consuming, yes, but not difficult.

Bo Thorsen,
Director, Viking Software.

-- 
Viking Software
Qt and C++ developers for hire
http://www.vikingsoft.eu



More information about the Interest mailing list