![]() |
Home · Overviews · Examples |
The QWidget::rect() function returns the widget's enclosing rectangle in the widget's own coordinates. The top-left corner of the rectangle is always (0, 0). Put the cannon in the bottom-right corner. Try adding a better keyboard interface. For example, make + and - increase and decrease the force and enter shoot. If you're bothered by the way the Left and Right keys work, change that too. [Hint: Reimplement QWidget::keyPressEvent().]t10/main.cpp
t10/main.cpp
Missing snippet: tutorials/tutorial/t10/main.cpp.
The constructor is mostly the same, but some new bits have been added.
Missing snippet: tutorials/tutorial/t10/main.cpp.
Missing snippet: tutorials/tutorial/t10/main.cpp.
We add a second LCDRange, which will be used to set the force.
Missing snippet: tutorials/tutorial/t10/main.cpp.
Missing snippet: tutorials/tutorial/t10/main.cpp.
Missing snippet: tutorials/tutorial/t10/main.cpp.
Missing snippet: tutorials/tutorial/t10/main.cpp.
We connect the force widget and the cannonField widget, just like we did for the angle widget.
Missing snippet: tutorials/tutorial/t10/main.cpp.
Missing snippet: tutorials/tutorial/t10/main.cpp.
In Chapter 9, we put angle in the lower-left cell of the layout. Now we want to have two widgets in that cell, so we make a vertical box, put the vertical box in the grid cell, and put each of angle and range in the vertical box.
Missing snippet: tutorials/tutorial/t10/main.cpp.
We initialize the force value to 25.Running the Application
We now have a force control.Exercises
Make the size of the cannon barrel be dependent on the force.
Copyright © 2008 Trolltech
Trademarks