PDA

View Full Version : Align QwtSlider and QwtPlot



justoit
3rd May 2011, 22:47
Hi everyone,

I am writing a control system simulation. A QwtSlider (the right one in the picture) is used to indicate a desired value while the left one follows its position using control system theory. Now I would like to have the QwtPlot draw the curve that the slider makes - basically use the slider as a seismometer needle. This works pretty well as you can see, but I still have one problem: I would like to align the slider and the plot so that the scales are the same. As you can see on the picture the Slider and the Plot both show the same value but there is a significal offset due to different sizes of the scales on the screen. Now I'm looking for a way to align the slider and the plot to have scales of exactly same size and same vertical origin so that they represent their values at the same vertical coordinates on the screen. Here's the pic:
http://i54.tinypic.com/vr8ow0.jpg

falconium
3rd May 2011, 23:28
Why don't you match the size of sliders to the size of axis Y?

justoit
4th May 2011, 00:13
Tried this by using ui.qwtPlot->axisWidget(QwtPlot::yLeft)->height() but it returned some weird results. To be honest there are so many possibilities to affect the visual appearance of qwt widgets that I do not know where to start looking for a solution.

Uwe
4th May 2011, 06:43
Of course you have to implement the layout code manually instead of using a QLayout by reimplementing the resizeEvent of the container widget ( parent of plot and slider ).

The scale and the geometry of the slider also needs be adjusted whenever the plot axis scale changes ( QwtScaleWidget::scaleDivChanged() ) and the geometry of this scale widget changes ( use an event filter and check its move and resize events ).

And finally you have to align your slider geometry taking QwtScaleWidget::startBorderDist() and QwtScaleWidget::endBorderDist() into count subtracting them from the border hints of the slider scale.

This all needs a deep understanding of the QwtPlot layout system and some sort of know how about Qt. Start with trying to understand what QwtScaleDraw::getBorderDistHint() is about.

Uwe

justoit
4th May 2011, 11:41
Thank you for the replies.

Reimplementing at low layouting level is something I will surely stay away from in this case as the amount of work I would have to put into this is simply not worth it (this is a project I do in my spare time, nothing work-related so I can live with that offset rather than spending hours with a task not directly related with my project). Thank you for the guide though.

In a quick test I removed the bottom scale of the plot and the scales were aligned well. I guess I might as well enlarge one of the scales by a certain offset, let's say have the scale on the plot go from -1000..1000 and the one on the slider work from -(1000+x)...1000 so that they still are aligned in the relevant area. The code should be a lot more simple than a complete rework of the layouting and painting functions.