0

I have text edit class that inherits QAbstractScrollArea, in Qt, Which I use to display some lines. When the number of lines become 1000, the oldest line is moved out, and new line takes its place.

But I store all the lines that are moved out, so that if the user scrolls up, I can display it to him when the scroll reaches its minimum boundary. I do this by following signal and slot.

connect(myArea->verticalScrollBar(),SIGNAL(valueChanged(int)),myArea,SLOT(myslot()));

and the slot is:

void myslot()
{
 if(this->verticalScrollBar()->value() == this->verticalScrollBar()->minimum())
 {
   //LOAD STORED LINE
 }
}

Problem

The problem is I want to scroll bar to behave as if there are more lines above. I want the scroll bar to reflect that there are lines above,(actually there are none), meaning is there a way in which I can tweak the scroll bar to not hit the minimum boundary as long as there lines stored to be displayed from the data structure?

What I tried

If( scroll bar hits upper boundary and data structure has lines in store)
{
 this->verticalScrollBar()->setValue( value greater than minimum);
}

But its not a smooth transition, like a normal scroll. Any ideas would be appreciated.

Sumeet
  • 7,440
  • 2
  • 21
  • 42
  • Remembering, that a scrollbar represents the navigation of a smaller visible range over a larger "virtual" range: `QScrollbar::minimum()` and `QScrollbar::maximum()` describe the virtual range. `QScrollbar::value()` describes the start of the visible range. About the length of the slider, I'm a little bit uncertain. (Whenever I used it, this was probably auto-determined e.g. from the size of viewport.) As I understood the doc., it can be controlled by `QScrollbar::pageStep()`. Everything before, I recalled from [Qt: QScrollbar](http://doc.qt.io/qt-5/qscrollbar.html#details). – Scheff's Cat May 12 '17 at 11:46
  • I'm afraid that I didn't get your problem. Could you, please, try to clarify it? – Scheff's Cat May 12 '17 at 11:47
  • @Scheff The problem is that I need to change the length of the slider , so that user will get the illusion that the lines are actually there( but they are not, because I feed the lines from a data strucuture AS SOON AS we hit the upper boundary). – Sumeet May 12 '17 at 13:09
  • @Scheff But the problem is that if the size of the slider is changed, Then I will not be able to get the correctly detect the upper boundary. – Sumeet May 12 '17 at 13:12
  • @Scheff Let me know if the problem is still unclear. – Sumeet May 12 '17 at 13:12
  • You must well-define a "virtual" range setting `minimum` and `maximum` as this is how the `QScrollbar` works. Changing `minimum` and `maximum` should update the scrollbar immediately. This may change the slider position also. If the latter is not desired some workaround is necessary. I once said an answer for this issue [Stop QTableView from scrolling as data is added above current position](http://stackoverflow.com/questions/42448836/stop-qtableview-from-scrolling-as-data-is-added-above-current-position/42460216?s=3|4.1426#42460216). – Scheff's Cat May 12 '17 at 13:19
  • Changing the `pageStep` should update the `QScrollbar` immediately also but this is just a guess. (I never tried it.) – Scheff's Cat May 12 '17 at 13:22
  • Yes it changes the size of scroll bar. – Sumeet May 12 '17 at 13:24
  • @Scheff But the problem is that say once lines become 1000 in number. Now whenever a new line comes, the first line is dropped. If another new line comes the second line is dropped. – Sumeet May 12 '17 at 13:25
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/144071/discussion-between-scheff-and-sumeet-singh). – Scheff's Cat May 12 '17 at 13:27

0 Answers0