PDA

View Full Version : Drawing an object on picture



anafor2004
7th February 2008, 07:14
Hi All
I have a project now, I want to draw an object (Dial) on picture which is in a frame.I try to make a car indicator. I am using a picture as a background and i want to move a dial on it.

wysota
7th February 2008, 09:45
And what is the problem?

marcel
7th February 2008, 11:16
And what is the problem?
He doesn't know how to draw the dial :)

Better subclass the frame or a QWidget and draw the background image in the paint event.
Next, draw a thin round rectangle from the paint event, from the indicator center, to whatever value you need.

The mobile end of the dial should be controlled by some member in your class, such as the current speed, or angle. In the paint event you should paint the dial according to this value.

wysota
7th February 2008, 11:30
QPainter::rotate() might come in handy.

anafor2004
7th February 2008, 13:00
today I achieved to do this, thank you for your interest.

QPainter painter(this);
int x1=0,y1=3,x2=0,y2=-3,x3=-90,y3=0;
QPoint points[] = { QPoint(x1, y1), QPoint(x2, y2), QPoint(x3, y3) };
painter.setRenderHint(QPainter::Antialiasing);
QPixmap pixmap;
pixmap.load("pencere.png");
painter.drawPixmap(0,0,pixmap);
painter.setPen(Qt::green);
QLinearGradient coneGradient(40,100,300,350);
coneGradient.setColorAt(0.5,Qt::white);
coneGradient.setColorAt(0.1,Qt::green);
coneGradient.setColorAt(1,Qt::black);
QMatrix matrix;
matrix.translate(0,20);
matrix.rotate(a);
painter.setMatrix(matrix);
painter.setBrush(coneGradient);
painter.setWindow(-107,-94,214,188);
painter.drawPolygon(points,3);

anafor2004
7th February 2008, 14:55
Hi
I have an other question, I will be appreciate if you answer it. I want to make an other two labels they will show battery level and A.D.C result.But they will have different backgorunds how may i do this . Do I have to make different classes for promoting and header files ? or may i use same class just make some changes in "paint event "which is i already used for above.