You have to animate the ellipse over the other ellipse by drawing one frame during every redraw cycle and not all frames during one redraw cycle. When you update the progress, call update() and your widget will redraw itself with the new value.
You have to animate the ellipse over the other ellipse by drawing one frame during every redraw cycle and not all frames during one redraw cycle. When you update the progress, call update() and your widget will redraw itself with the new value.
sorry but may be it would sound absurd,but do you mean that the number of times i have to draw the green circle is the number of times i have to implement the paint function...it somehow doesnt make sense to me..but this is what i am able to understand..You have to animate the ellipse over the other ellipse by drawing one frame during every redraw cycle and not all frames during one redraw cycle
no.
You need one paint() function.
This function is called when the CURRENT state of your widget/item is to be drawn.
I.e. you implement this function to paint your circle at the one position that corresponds to your current angle/progress value.
Qt Code:
painter->drawEllipse(0, 0, 200, 200); painter->translate(dx,dy); // draw one circle at the position that is stored in your widget // i.e. your widget knows its state (in numbers): just visualize it painter->rotate(yourCurrentAngleAsStoredInSomeWidgetMemberVariable); painter->translate(0,91); painter->drawEllipse(0,0,15,15);To copy to clipboard, switch view to plain text mode
When progress advances, you increase your "yourCurrentAngleAsStoredInSomeWidgetMemberVariabl e" variable and call update().
When Qt sometime later causes a repaint, paint() gets called and you just access the current value of that variable.
This results in an animation.
I.e. you do not animate inside paint().
paint() paints snapshots, no movement or animation whatsoever.
Animation results from the repeated calls (of update() -> paint()) as a sequence of such snapshots.
HTH
does this has to be done by signal/slots in my paint() function ?When progress advances, you increase your "yourCurrentAngleAsStoredInSomeWidgetMemberVar iabl e" variable and call update().
where should these call be make and are you sure about update()->paint()..because it doesnt workAnimation results from the repeated calls (of update() -> paint()) as a sequence of such snapshots.
no, as i wrote in an earlier posting:
add a slot to your widget/item, call it advance() -or whatever, let's assume you called it advance()-
(and don't forget the Q_OBJECT macro in your class declaration!)Qt Code:
YourItem::advance() { angle +=10; angle %=360; update(); }To copy to clipboard, switch view to plain text mode
somewhere else:
Qt Code:
QTimer timer; yourItem->connect(&timer, SINGAL(timeout()), SLOT(advance())); timer.start(25);To copy to clipboard, switch view to plain text mode
(Of course your timer must not be/go out of scope, otherwise the animation stops.
Perhaps it is best to declare it as QTimer* in your widget and allocate it with new.)
i have tried to implement the thing this way ,but it wont work..
now i have two questions when i debug the code compiler says that
'warning: Object::connect: No such slot QObject::advance()'
and most importantly am i doing right thing concept wise..
Qt Code:
ProgressWidget::ProgressWidget() { r1.setRect(85,-13.5,30,30); dx = 100; dy = 100; connect(timerProg,SIGNAL(timeout()),this,SLOT(advance())); timerProg->start(1000); } { //painter->save(); painter->drawEllipse(0, 0, 200, 200); painter->translate(dx,dy); painter->rotate(rotation); painter->translate(0,91); painter->drawEllipse(0,0,15,15); } { qreal penWidth = 150; } void ProgressWidget::advance() { rotation = rotation + 30; this->update(); } ProgressWidget::~ProgressWidget() { }To copy to clipboard, switch view to plain text mode
Qt Code:To copy to clipboard, switch view to plain text mode
also surprisingly if i add Q_OBJECT macro it throws a compile time error..and says 'connect undeclared'
sorry for the last post..it was a mistake from my side ..anyways ..the green bar moves around the grey circle but if i only minimized and then maximized my output screen...it issnt moving on the screen if i dont minimize it...to simplify it doesnt move in normal conditions
The code looks ok (perhaps the 1000ms you pass in start is a bit large).
If you provide (attachment) a self-contained compilable example, we can try to help you with the minimize/maximize issue.
i have tried it with lesser value ..but still the same result...in the docs i found this statement..
..my class hiererachy is something like i am calling from a main function a class named trainingThis function does not cause an immediate paint; instead it schedules a paint request that is processed by QGraphicsView after control reaches the event loop
such as
class training: public QGraphicsView..
from this class i call an instance of
class scene such as
class scene: public QGraphicsScene
and after that in hierarchy comes the class item
class item: public QGraphicsItem..
and all the work i am doing for now is done in item class..so again coming to the docs i think this line has soemthing to do with the situation i am facing...
Put debug statements (qDebug() << __PRETTY_FUNCTION__ inside the slot and the paint() function... that way you can see if these get called as often as expected.
i am using eclipse integration with qt ..and it shows that the paint() and advance slots are called consecetively...
i think this problem is due to something else ,may be as i posted in my previous post...
what do you mean ?,the code or .exe or something else....i didnt get itIf you provide (attachment) a self-contained compilable example,
Well, compilable kind of implies source code, right ?
I am Linux based, so your exe would not help me. And I hardly could debug/modify it.
If you can post a (minimal) compilable example (as a .zip, or .tar.gz file) I could try it out and help.
Hi..
I have attached all the source ,header and .pro file..i hope you would be able to figure out something...just one small correction,please remove TrainingUI.qrc from the .pro file
The error is: your bounding rect is not correct.
Your code does try to repaint, but the incorrect bounding rect prevents the relevant area to be redrawn.
Return something like QRectF(0,0,300,300) (which errs, too, but on the 'safe' side). And you see will something moving.
Please read up in the docs on QGraphicsItem::boudingRect and perhaps QGraphicsItem::shape.
HTH
Thanks it worked...u deserve a great Thanks ..for all the way helping me into this...and answering sometime il/logical questions
Bookmarks