0

I have a QStandardItemModel and it contains my data which has around 5000 rows. I want to insert the data into QScrollArea in batches. If I insert it altogether the performance becomes really slow. Hence I want to add the data when it is required by the viewport in the QScrollArea. At first I have loaded the QScrollArea with 500 rows. When the user scrolls I want further data to be added to the viewport of the QScrollArea.

Does anyone have an idea on how to go about this ??

Sandy
  • 11
  • 4
  • Are you looking for something like [`fetchMore`](https://doc.qt.io/qt-5/qtwidgets-itemviews-fetchmore-example.html)? – Mike Sep 23 '16 at 20:34
  • Maybe you should profile the code running and see what function calls take the most and then decide how to optimize it. For me the similar case QSortFilterProxyModel::data function taking to much time to decrypt some data so I cached it and the code started to fly. – Alexander V Sep 23 '16 at 22:00
  • @Mike: Yupp "fetchMore" & "canFetchMore". I already had a look at the Qt example but I am not sure how to implement it for QScrollArea – Sandy Sep 24 '16 at 17:30
  • @Sandy , please paste your code, so that we can help you. Try organizing it as an [MCVE](https://stackoverflow.com/help/mcve), I don't get how are you using your `QScrollArea`. – Mike Sep 24 '16 at 17:39

1 Answers1

0

QScrollArea (http://doc.qt.io/qt-4.8/qscrollarea.html) inherits the function

 QScrollBar * QAbstractScrollArea::verticalScrollBar() const

So you could get the ScrollBar like this

QScrollBar* scroll = ui->scrollarea->verticalScrollBar();

and connect the value to a slot

QObject::connect( scroll , SIGNAL(valueChanged(int)) ,this , SLOT(addvalues(int)) );

In the addvalues slot you can check the scrollbar position and add values if needed.

Lorenzo Norcini
  • 192
  • 1
  • 1
  • 14
  • I already tried using it but in my case I want to add custom widgets(2 QLabels & 1 QPushButton). I tried playing around with it but couldn't find a solution. – Sandy Sep 24 '16 at 17:34