View Full Version : Qwt_Slider, how to create hot spots in its scale?
Hogwarts
18th February 2010, 18:41
Hello!
I need help in what follows: I'm using Qwt library, specifically its slider. I need to change the backgroud color to its scale. At first, I need to know at least how to do this, so that perhaps I get to do what I really want, that is creating hot zones in the scale. I explain: I need to divide the scale into zones, matching, for example, green color to values between 0 and 60, yellow between 61-90 and so on. I'm trying to develop graphic components for a configuration editor of a SCADA. I'm using QT and Qwt. Any help is welcomed.
Thanks in advance.
Uwe
20th February 2010, 12:49
You have to overload QwtSlider::paintEvent() ( or another virtual draw method ). Here you have to calculate your rectangles and fill them with a color using QPainter.
Uwe
Hogwarts
25th March 2010, 02:59
I have implemented a class that inherits from QwtScaleDraw, in order to overwrite the method draw, to be used in the hot zones in the scale, but it seems that I can't use an object of this class, in the method setScaleDraw(QwtScaleDraw*) of another class that I implement, that inherits from QwtSlider, anyway, as I've been using this library from a little while, it is difficult for me. Could you give me a more specific indication? Thanks.
Hogwarts
22nd April 2010, 03:06
There are several solutions to the subject in question, this is what I found most suitable:
I overloaded the function QwtSlider::PaintEvent() as follows:
void CustomSlider::paintEvent(QPaintEvent *event)
{
const QRect &ur = event->rect();
if ( ur.isValid() )
{
#if QT_VERSION < 0x040000
QwtPaintBuffer paintBuffer(this, ur);
draw(paintBuffer.painter(), ur);
#else
QPainter painter(this);
if(editHotZones())
drawHotZones(&painter);
draw(&painter, ur);
#endif
}
}
the only thing new here is:
if(editHotZones())
drawHotZones(&painter);
drawHotZones is a function used to draw zones with differents colors and ranges:
void CustomSlider::drawHotZones(QPainter* painter)
{
QRect r;
if(orientation() == Qt::Horizontal)
{
if(scalePosition() == TopScale)
{
r.setRect(scaleDraw()->scaleMap().transform(startHotZone1()),
scaleDraw()->pos().y() - zoneHeight(),
scaleDraw()->scaleMap().transform(endHotZone1()) - scaleDraw()->scaleMap().transform(startHotZone1()),
zoneHeight());
painter->fillRect(r, colorZone1());
r.setRect(scaleDraw()->scaleMap().transform(endHotZone1()),
scaleDraw()->pos().y() - zoneHeight(),
scaleDraw()->scaleMap().transform(endHotZone2()) - scaleDraw()->scaleMap().transform(endHotZone1()),
zoneHeight());
painter->fillRect(r, colorZone2());
r.setRect(scaleDraw()->scaleMap().transform(endHotZone2()),
scaleDraw()->pos().y() - zoneHeight(),
scaleDraw()->scaleMap().transform(customMaxValue()) - scaleDraw()->scaleMap().transform(endHotZone2()),
zoneHeight());
painter->fillRect(r, colorZone3());
}
(...)
}
I hope will be helpful, if you need to do something similar
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.