Qt Made Easy!
Last updated: 1998/07/20 16:35:38


  Main Features Help Mailing List Tutorial FAQ Download

Contents
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5

In this project we will make a self playing animation as well as play and stop buttons with some simple utilization of the Qt drawing tools.


Hopefully you're coming from the previous demo, if it bored you and you came here you can pull up from that last from you QtEZ distribution in the demos/tutorial/ directory.
Anyway, assuming you're coming from the last demo, lets first start with the only component we'll be adding to this project, and that is a new one to us, the timer, so as we have before drop it onto the dialog, and set the attributes so that its activity is false, in the attributes, as we have before. Then let's go into the slot connections of the two buttons (as we've done before, and is documented in Signals & Slots page. Go ahead and disconnect the showNext() and showPrevious() connections, and connect the timer's timeout() signal to the showNext() slot. Then clear the caption to both of the buttons. This is where we'll do some drawing. But first let's create two new public slots make two of them called "void play()" and "void stop()", once done connect the left button's clicked signal to the play slot, and the right one's to the stop slot. Then let's add our code.
Go ahead and pull up the source code to the play() function and add the following code.

timer1->start(100,FALSE);

This will start the timer going every 100 ms. Then in the stop() slot, let's add the following.

timer1->stop();

This will obviously make the timer stop counting, and hence stop the animation. On to the final step and that's drawing a little bit on the buttons, so pull up the left button in the Source Editor. We must add a different kind of function then we have before, so add a new member, only this time make sure virtual is checked, and protected is marked as well. Then add the prototype "void drawButtonLabel(QPainter *p)". Go ahead and do this for both buttons so that they each of this member. Then pull up the left button's drawButtonLabel member, this will be the play button. So let's draw a little play graphic.

QBrush b("black");
QPointArray xy;

xy.putPoints(0,3, 45,5, 60,15, 45,25);

p->setBrush(b);
p->fillRect(35,5, 5,20,b);
p->drawPolygon(xy,FALSE,0,3);

Then let's draw the pause (or stop) button's label. So in it's drawButtonLabel member add the following.

QBrush b("black");

p->setBrush(b);
p->fillRect(45,5, 5,20,b);
p->fillRect(55,5, 5,20,b);

Now our project should be complete, simply go to the Menubar and select run | run.


Project Screen Shot | Next | Previous | Contents


Mail Author