0

I am working on a qwtPlot and have implemented custom scrollbars to illustrate the position of things on the plot when zooming in (in regards to the whole thing - so basically the percentage).

Now, everything works fine, apart from the moment, when I do any zooming or panning right at the beginning (or simply when I see the whole plot and then I want to zoom in).

This is a slot I am using to refresh the appearance of the scrollbar:

void ScrollHorizontal::refreshAfterChanges() {
setValue(myPlot->getLowerBound(QwtPlot::xBottom));
setPageStep(myPlot->get_X_delta());
setSingleStep(myPlot->get_X_delta()/10);
setMaximum(myPlot->dataFromSources->lastTimeValMicro()-pageStep());  
update();
printV("HorizontalScroll::setValue",myPlot->getLowerBound(QwtPlot::xBottom));
printV("value", value());
printV("pageStep", pageStep());

in the constructor I set the maximum to 0 (just in case, but it doesn't change anything)

The last 3 lines print out some values useful for debugging. What I found out thanks to them is that the slot is executed correctly, but the setValue(int) function doesn't work as I would expect it to:

//printed values right after starting the program
HorizontalScroll::setValue=0
value=0
pageStep=7320

//printed values after using the zoomer once
HorizontalScroll::setValue=956.316
value=0
pageStep=2225

Then, when I move the plot a tiny bit, e.g. zoom it 1.1 times, the setValue works properly and value() return the same thing I set. But if I go to the 100% view (the starting point) I get the same problems again.

Just to illustrate it, here are some screenshots:
http://tinypic.com/view.php?pic=2znph7s&s=8#.UvNkDoZhauY
(100% view, right before zooming in)

http://tinypic.com/view.php?pic=ke7nn9&s=8#.UvNkYIZhauY
(badly set qscrollbar)

genau
  • 184
  • 1
  • 5
  • 16
  • 2
    You need to call `setMaximum` before `setValue`. You cannot set a value that is greater than the current maximum. – Pavel Strakhov Feb 06 '14 at 13:16
  • I mentioned above that I set Maximum to 0 in the constructor. But after changing it to my x axis maximum (the change was made in the constructor), it still doesn't work. So this doesn't solve the problem – genau Feb 06 '14 at 15:00
  • What did work is refreshing the values twice: `void CentralWidget::adjustScrolls(){ hScroll->refreshAfterChanges(); vScroll->refreshAfterChanges(); if(hScroll->value()==0) hScroll->refreshAfterChanges(); if(vScroll->value()==0) vScroll->refreshAfterChanges(); } ` which seems a really crude solution - so if anyone has any idea what would be better, I'd like to know :) PS.I would post it as the answer, but unfortunately I don't have enough reputation to do it yet. – genau Feb 06 '14 at 15:17
  • Are you really sure that current maximum is greater than the value you're trying to set? Put test output before setValue to check `maximum()` return value. – Pavel Strakhov Feb 06 '14 at 19:25
  • You are right - the problem appeared when the maximum was made 0 by the line `setMaximum(myPlot->dataFromSources->lastTimeValMicro()-pageStep()); `(which I had to do if I wanted the "slider" (the page step) to take up the whole length of the scrollbar) – genau Feb 07 '14 at 10:05

1 Answers1

1

Ok - problem was caused by the line

setMaximum(myPlot->dataFromSources->lastTimeValMicro()-pageStep());  

It was setting the maximum to 0 sometimes. why? I wanted the slider to take up the whole length of the scrollbar so that at the beginning when the plot was shown in 100% view, you couldn't scroll it and I could achieve that by setting the pagestep to my plot's maximum value and the maximum to 0.

But that caused the setValue(int)problem - you can't set a value bigger than the maximum.

So what finally worked for me is:

double valueToSet=myPlot->getLowerBound(QwtPlot::xBottom);
if(valueToSet>maximum())
    setMaximum(valueToSet);

setValue(myPlot->getLowerBound(QwtPlot::xBottom));
setPageStep(myPlot->get_X_delta());
setSingleStep(myPlot->get_X_delta()/10);
setMaximum(myPlot->dataFromSources->lastTimeValMicro()-pageStep());
update();
genau
  • 184
  • 1
  • 5
  • 16
  • btw, this was also a rather crude solution, especially because I assumed that the min value was 0. Now when that is not the case I now have in the constructor: `setRange(myPlot->getAxisMin(axis), myPlot->getAxisMin(axis)); setValue(myPlot->getLowerBound(axis)); setPageStep(myPlot->getAxisDelta(axis)); range=myPlot->getAxisMax(axis)-myPlot->getAxisMin(axis);` And in the slot: `setValue(myPlot->getLowerBound(QwtPlot::xBottom)); setPageStep(myPlot->getAxisDelta(QwtPlot::xBottom)); setMaximum(range-pageStep()+minimum());` – genau Feb 11 '14 at 08:06