|
AngularMeter background |
Posted by lf460 on Mar-02-2015 10:30 |
|
I want to know that how to make the background of AngularMeter transparent?
I used the Chart::Transparent, but it had no effect. The code as follow:
AngularMeter *m = new AngularMeter(200, 200, Chart::Transparent);
Anyone could help me, please?
Thanks, |
Re: AngularMeter background |
Posted by Peter Kwan on Mar-03-2015 04:26 |
|
Hi lf460,
If the chart is output in PNG, it will preserve the transparency.
I see you code is in C++. Are you using MFC or Qt as the GUI framework? Standard MFC
controls do not support transparency. Instead of using transparency, one method you may
consider is to set the chart background color to the same color as the Form. In some
ChartDirector MFC sample code, the following utility is used to detect the background color
of the Form:
//
// Get the default background color
//
int MyDialog::getDefaultBgColor()
{
LOGBRUSH LogBrush;
HBRUSH hBrush = (HBRUSH)SendMessage(WM_CTLCOLORDLG,
(WPARAM)CClientDC(this).m_hDC, (LPARAM)m_hWnd);
::GetObject(hBrush, sizeof(LOGBRUSH), &LogBrush);
int ret = LogBrush.lbColor;
return ((ret & 0xff) << 16) | (ret & 0xff00) | ((ret & 0xff0000) >> 16);
}
Please kindly let me know if the above is sufficient for your case.
Regards
Peter Kwan |
Re: AngularMeter background |
Posted by lf460 on Mar-03-2015 09:56 |
|
Thank you Peter for your reply! I am using Qt as the GUI framework. The code as follow:
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget* widget = new QWidget();
QPalette palette;
palette.setColor(QPalette::Background, QColor(0,128,0));
widget->setPalette(palette);
QChartViewer viewer(widget);
double value = 65.5;
AngularMeter *m = new AngularMeter(200, 200, Chart::Transparent);
m->setRoundedFrame();
// Set the meter center at (100, 100), with radius 85 pixels, and span from -135 to
+135 degress
m->setMeter(100, 100, 85, -135, 135);
// Meter scale is 0 - 100, with major tick every 10 units, minor tick every 5 units,
and micro tick every 1 units
m->setScale(0, 100, 10, 5, 1);
// Disable default angular arc by setting its width to 0. Set 2 pixels line width for
major tick, and 1 pixel line width for minor ticks.
m->setLineWidth(0, 2, 1);
m->addRing(0, 90, Chart::metalColor(0x9999dd)); // Set the circular meter surface
as metallic blue (9999DD)
m->addRing(88, 90, 0x6666ff); // Add a blue (6666FF) ring between radii 88 - 90 as
decoration
// Set 0 - 60 as green (99FF99) zone, 60 - 80 as yellow (FFFF00) zone, and 80 -
100 as red (FF3333) zone
m->addZone(0, 60, 0x99ff99);
m->addZone(60, 80, 0xffff00);
m->addZone(80, 100, 0xff3333);
// Add a text label centered at (100, 135) with 15 pts Arial Bold font
m->addText(100, 135, "Rate", "arialbd.ttf", 15, Chart::TextColor, Chart::Center);
// Add a text box centered at (100, 165) showing the value formatted to 2 decimal
places,
// using white text on a black background, and with 1 pixel 3D depressed border
m->addText(100, 165, m->formatValue(value, "2"), "arial.ttf", 8, 0xffffff,
Chart::Center)->setBackground(0x000000, 0x000000, -1);
// Add a semi-transparent blue (40333399) pointer at the specified value
m->addPointer(value, 0x40333399);
// Output the chart
viewer.setChart(m);
widget->resize(400,400);
widget->show();
return app.exec();
}
Regards
lf460
|
Re: AngularMeter background |
Posted by Peter Kwan on Mar-04-2015 00:51 |
|
Hi lf460,
For your case, the preferred method is to set the background color to the same color as
your widget. For example:
QColor color = widget->palette().color(QPalette::Background);
int bgColor = (color.red() << 16) | (color.green() << 8) | color.blue();
AngularMeter *m = new AngularMeter(200, 200, bgColor);
There is another method, which is to modify the "QChartViewer.cpp" source code. To do
this, search for the line that contains the word "Chart::BMP" and change it to "Chart::PNG".
This will allow the QChartViewer to support transparency.
Hope this can help.
Regards
Peter Kwan |
Re: AngularMeter background |
Posted by lf460 on Mar-04-2015 10:06 |
|
Thank you Peter very much!
It is wonderful. I did it according to your suggestions.
Thanks again. |
|