Tutorial Page Three
In this project we will be making our flip book of sorts utlizing: the
Globals Editor, the
Source Editor, and some
Signals & Slots.
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, first let's delete our
toggleShow() function. Do this by selecting project1 in the source editor, then
toggleShow(), then goto file on the menubar and select delete function. Now
let's select the label with the pixmap on it, so click on it so it becomes
highlighted. Then go to the Menubar
and select
edit | copy. Make sure project1 is the current parent (by clicking on it), and
select edit | paste on the Menubar. When you do this it's going to ask if you
want to incorporate into an array. Click yes and continue pasting and clicking
yes 5 more times.
Now we have to go through and make each have a unique pixmap so it's a flipbook.
so right click on any of the labels (they'll be behind one another). This will
bring up the Attributes select label1[1] in
the upper most combobox (as we have before), and set it's pixmap to the next
frame bmp in demo/tutorial/. And do this all the way up to label1[6].
Once done with this lets resize the button on the dialog so it is only about
as wide as half the pixmap above it, and drop a button to the right of it
about the same widget and set the captions of each to "Next", and "Previous".
Go ahead and select some unique background colours for each of these buttons,
and set whatever other desired attributes, then we'll continue with the project.
Double click on project1. This will bring up the
Source Editor. Make sure project1 is in the leftmost combo box. Then go to
file | new member, and add "int frame", this will add a class wide member, in
this case just an integer. Then go to the rightmost combo box and select
the constructor, let's intialize frame to 0, so in the constructor put.
frame = 0;
label1[frame]->raise();
This will also bring the first frame to visibility. Now let's add something to
the main header, so go to the menubar, and select windows | globals editor. and
in there type.
#define MAXFRAMES 7
We do this because there are 7 frames in this flipbook. Now lets return to the
Source Editor and add two public slots as we have done before, one with the
prototype "void showNext()" and the other with "void showPrevious()". Once this
is done make sure showNext() is select in the member list, and add the
following source code.
if(frame < MAXFRAMES)
   frame++;
else
   frame = 0;
label1[frame]->raise();
Doing will make is so it will iterate through 0 and 7 multiple times. With this
out of the way we need a similar function for showPrevious reading:
if(frame > 0)
   frame--;
else
   frame = MAXFRAMES;
label1[frame]->raise();
Now we're on to the final step and that's connecting the
Signals & Slots as we have before, so I'll
leave you to doing so. (Just connect the next button to showNext() and the
previous button to showPrevious()) and you should be all done! Run the program
and you have a little flip-book with buttons allowing you to move both
directions.
Project Screen Shot |
Next | Previous |
Contents