[Interest] Pause QTableView while model continues to update
Francis Herne
mail at flherne.uk
Thu Jul 9 16:06:49 CEST 2020
On Thursday, 9 July 2020 14:58:05 BST Francis Herne wrote:
> On Wednesday, 8 July 2020 19:20:33 BST Murphy, Sean wrote:
> > Is there a way to temporarily pause a QTableView while the underlying
> > model
> > continues to update?
> >
> > My scenario:
> > - I have two separate QTableViews connected to a single model.
> > - The model is being fed from a continuously updating data source, i.e. a
> >
> > sensor. - One of the views needs to remain live at all times - so as the
> > model's data updates, the view updates immediately.
> >
> > For the other view, the user should be able to "pause" that view's
> > display,
> > spend as much time as they want looking at the data on that paused table,
> > and then whenever they choose, they can un-pause that view and it returns
> > to updating constantly. This view has to remain fully usable (scroll bars
> > work, clicks work, etc.) while paused.
> >
> > The only idea I have at the moment is to have a second model object, that
> > is identical to the first one, except that it isn't connected to the
> > sensor. At the time the user wants to pause the view, I copy the current
> > data out of the main model into the second model, swap out the paused
> > view's model out to the second model, and then swap it back to the main
> > model when the user wants to go back live.
> >
> > Am I missing something easier? The only other idea I had was that I could
> > try to change the second view from a pure QTableView to one that inherits
> > from QTableView and then have my own slot that disconnects/connects the
> > signals between the model and that view based on the when the user wants
> > to
> > pause/resume.
> >
> > Sean
>
> You could have a QProxyModel subclass with a 'timeRange' (or so) property.
>
> When set to null it would simply relay everything to the backing model,
> otherwise it would provide only the relevant subset.
>
> I think this would be much easier than copying the data, or swapping models
> in and out.
>
> -Francis H
To be more precise - you should subclass QSortFilterProxyModel and override
`filterAcceptsRow()` and/or `filterAcceptsColumn()` to hide data outside the
time period you want.
More information about the Interest
mailing list