PDA

View Full Version : QwtDial - multiple Background color



Maximus2
25th November 2013, 04:03
Hi guys,

Here is my current QwtDial (https://www.dropbox.com/s/h24ybi89ykqm8m3/or1.png)
Here is what I would like (https://www.dropbox.com/s/eh5p2orodyianb8/or2.png) (forgive my painting skills)

I can put one color that fit the circle totally but I'm failing at using multiple color at the same time.


QPalette palette;
palette.setColor( QPalette::WindowText, QColor(89, 130, 67) ); //GREEN 90-270
palette.setColor( QPalette::WindowText, QColor(35, 53, 216) ); //BLUE 0-90
palette.setColor( QPalette::WindowText, QColor(168, 18, 18) ); //RED 270-360


I'm using the DialBox example modified for my need found in the qwt/examples
Thanks if you can give a hand to a Qwt newbie!

Uwe
25th November 2013, 18:41
You have to overload drawScaleContents using QPainter::drawPie().

Uwe

Maximus2
26th November 2013, 13:18
Thanks for your answer, I will try that and post the resulting code when it's working

[Edit]

Got it to work, QPainter is really powerfull ! (see code below)



//////////////////////////////////////////////////////////////////////////////////////////////////
/*!
Draw the contents inside the scale
Paints nothing.

\param painter Painter
\param center Center of the contents circle
\param radius Radius of the contents circle
*///////////////////////////////////////////////////////////////////////////////////////////////////
void myQwtDial::drawScaleContents( QPainter *painter, const QPointF &center, double radius ) const {



qDebug() << "X: " << center.x() << "Y : " << center.y();
qDebug() << "RADIUS" << radius;


QRectF rectangle(center.x()-radius, center.y()-radius, radius*2, radius*2);


painter->setBrush(QBrush(Qt::darkGreen));
painter->drawPie(rectangle, (0 * 16), (180 * 16) );

painter->setBrush(QBrush(Qt::blue));
painter->drawPie(rectangle, (180 * 16), (90 * 16) );

painter->setBrush(QBrush(Qt::red));
painter->drawPie(rectangle, (270 * 16), (90 * 16) );

}

Maximus2
26th November 2013, 19:13
Last questions,

1- Would it be possible to cut the QwtDial in half like this? (https://www.dropbox.com/s/lecoo9zs215ub60/or3.png)

2- Would it be possible to hide the black line in the circle, see example here (https://www.dropbox.com/s/purm8h9v3u0x20c/or4.png), I guess QPainter add it automatically when using drawPie()?
[ANSWER : Use "painter->setPen( Qt::NoPen )" on your painter, simple!]

Thank you!