I'm mostly new at this but I'm attempting to build a virtual car dashboard. My main problem has arisen in trying to put text within a dial. I'm using the qwt designer plugins but I need to further style the dials from the code. Copying from the qwtdials speedometer example I attempted to add "rpm x1000" with this code:
#include <QtGui>
#include <qpainter.h>
#include <qwt_dial_needle.h>
#include "dashcar.h"
#include "ui_dashcar.h"
#include <QtGui>
#include <qpainter.h>
#include <qwt_dial_needle.h>
#include "dashcar.h"
#include "ui_dashcar.h"
To copy to clipboard, switch view to plain text mode
ui
->Main_Dial_Rpm
->drawScaleContents
(QPainter *painter,
const QPoint ¢er,
int radius
) const {
QRect rect
(0,
0,
2 * radius,
2 * radius
- 10);
rect.moveCenter(center);
painter->setPen(color);
const int flags = Qt::AlignBottom | Qt::AlignHCenter;
painter->drawText(rect, flags, "rpm x1000");
}
ui->Main_Dial_Rpm->drawScaleContents(QPainter *painter,
const QPoint ¢er, int radius) const
{
QRect rect(0, 0, 2 * radius, 2 * radius - 10);
rect.moveCenter(center);
const QColor color = palette().color(QPalette::Text);
painter->setPen(color);
const int flags = Qt::AlignBottom | Qt::AlignHCenter;
painter->drawText(rect, flags, "rpm x1000");
}
To copy to clipboard, switch view to plain text mode
however I get the following errors:
dashcar.
cpp: In constructor ‘DashCar
::DashCar(QWidget*)’
:dashcar.cpp:33: error: expected primary-expression before ‘*’ token
dashcar.cpp:33: error: ‘painter’ was not declared in this scope
dashcar.cpp:34: error: expected primary-expression before ‘const’
dashcar.cpp:34: error: expected primary-expression before ‘int’
dashcar.cpp:34: error: expected ‘;’ before ‘const’
make: *** [dashcar.o] Error 1
dashcar.cpp: In constructor ‘DashCar::DashCar(QWidget*)’:
dashcar.cpp:33: error: expected primary-expression before ‘*’ token
dashcar.cpp:33: error: ‘painter’ was not declared in this scope
dashcar.cpp:34: error: expected primary-expression before ‘const’
dashcar.cpp:34: error: expected primary-expression before ‘int’
dashcar.cpp:34: error: expected ‘;’ before ‘const’
make: *** [dashcar.o] Error 1
To copy to clipboard, switch view to plain text mode
Also, if possible I would like to know how to turn the dial face different colors to serve as a shift light, and I guess from what I read it involves a similar process.
Any ideas?
Bookmarks