Then set the ticks to 500, 1000 and modify how the tick labels are represented:
Qt Code:
{ }To copy to clipboard, switch view to plain text mode
HTH,
Uwe
Then set the ticks to 500, 1000 and modify how the tick labels are represented:
Qt Code:
{ }To copy to clipboard, switch view to plain text mode
HTH,
Uwe
That could work to control what's written into each label. I am overriding a method from Qt. Is it OK if I declare this overriden method into my own code, or do I need to do anything special?
Anyway I still don't know how to tell the QwtSlider where to put labels, only how to format them. How can I do that?
Usually it's done this way:
Of course you can also calculate and assign the ticks manually ( even if I don't see any good reason in your situation ) using a QwtScaleDiv object, but then code has to be like this:Qt Code:
ui.timeSampleSlider->setScale( 500, 9500, 500 ); ui.timeSampleSlider->setRange( 500, 9500 ); ui.timeSampleSlider->setScaleMaxMinor( 0 ); // when you want to disable the minor ticksTo copy to clipboard, switch view to plain text mode
UweQt Code:
ui.timeSampleSlider->setRange( 500, 9500 );To copy to clipboard, switch view to plain text mode
But I have already tried the first code (but with 1000 between each tick, not 500 as you write here), and I'm getting the slide I put an image about, with ticks on 1000, 2000, 3000, ... 9000, when my selectable points are in 500, 1500, 2500, ... 9500. I still don't know how to solve that.
By replacing 1000 by 500 - or if you want to have the ticks on 500, 1500 only ( but not on 1000 ) the second option I have posted ( of course without the ticks at 1000, 2000 ... ) is what you need.
Uwe
Last edited by Uwe; 7th September 2012 at 09:39.
I have and error when using setScale method: none of the 4 overloads could convert all the argument types.
Qt Code:
for(int i=0; i<timeSamples.size(); i++) ticks[0].append(timeSamples.at(i));//<<0.5<<1.5<<2.5<<3.5<<4.5<<5.5<<6.5<<7.5<<8.5<<9.5; ui.timeSampleSlider->setRange(start, end); ui.timeSampleSlider->setScaleMaxMinor(0); ui.timeSampleSlider->setValue(start); ui.timeSampleSlider->setEnabled(true);To copy to clipboard, switch view to plain text mode
Of course not - ticks is a parameter of the QwtScaleDiv constructor. Are you familiar with C++ ?
Uwe
Ok, it was a mistake while reading. SHould have copy-pasted your lines.
Anyway it doesn't work. It looks just as my second test (see second image at the first post). And it allows user to stop at any possible value into the range, which didn't before. I guess that's for not using the third parameter at setRange method.
Any other possible approach?
I am assigning the values I want for my ticks. That's what I was trying to do myself even before posting this. I have copied your lines of code exactly and if my input ticks are 500, 1500, 2500... 9500, the only labels I'm getting are 2000, 4000, 6000 and 800, just as at the beginning.
My code is the one I shown two answers ago, when I had a mistake with the setScale, but now that method is jsut as you suggested. Doesn't work.
Qt Code:
for(int i=0; i<timeSamples.size(); i++) ticks[0].append(timeSamples.at(i)); //Timesamples has inside: 500, 1500, 2500...9500 ui.timeSampleSlider->setRange(start, end); ui.timeSampleSlider->setScaleMaxMinor(0); ui.timeSampleSlider->setValue(start); ui.timeSampleSlider->setEnabled(true);To copy to clipboard, switch view to plain text mode
Build and run the application below ( unmodified - please no more modifications from your code ).
Isn't this what you want ?
Qt Code:
#include <qapplication.h> #include <qwt_slider.h> #include <qwt_scale_div.h> int main( int argc, char **argv ) { << 4500 << 5500 << 6500 << 7500 << 8500 << 9500; slider.setRange( 500, 9500, 1000 ); slider.show(); return a.exec(); }To copy to clipboard, switch view to plain text mode
This is really a "schwere Geburt",
Uwe
RomanRdgz (10th September 2012)
Ok, it does work now. The problematic line was:
Qt Code:
ui.timeSampleSlider->setScaleMaxMinor(0);To copy to clipboard, switch view to plain text mode
Which is weird, but without that line my code works exactly as yours. Thanks for your time!
One more question: about the method you gave me before to customize the labels, how could I use it?
I am accessing the QwtSlider from the ui, with ui.timeSampleSlider, as you have already seen when I showed code here. I know I can get the ScaleDraw associated to my QwtSlider with the scaleDraw() method, but I don't know how to write the function you gave me then.
I can think of:
Qt Code:
{ }To copy to clipboard, switch view to plain text mode
which is obviously wrong, but I can't think of how to access to the ScaleDraw. By the way, I'm writting this method into my code, into the same cpp file I have been working before to set the ticks where I wanted.
How can I use this method then? Thanks once more!
Assigning the YourScaleDraw object has to be done before you set the ticks !Qt Code:
{ public: { } }; ui.timeSampleSlider->setScaleDraw( new YourScaleDraw() );To copy to clipboard, switch view to plain text mode
But please stay to Qwt related questions, when posting here. There are other forums dedicated to C++.
Uwe
RomanRdgz (10th September 2012)
Bookmarks