Create the Counters custom widget shown in Figure 11.8. The widget should show a 3 x 3 grid, with each square either blank (showing just the background color) or with a red or yellow ellipse. The state of any grid square should change from blank to red to yellow and back to blank in an endless cycle. Changes of state should occur when the user clicks a square or presses the spacebar on a square. The keyboard focus should be shown by drawing the square with a thick blue pen instead of the normal thin black pen used for the other squares. The user should be able to change the focused square by clicking a square or by using the up, down, left, and right arrow keys to move the focus.

Make sure that you provide a size hint and minimum size hint so that the widget has good resizing behavior and cannot be shrunk too small. The paint event is quite short, but slightly subtle; you will probably need to save and restore the painter's state, using QPainter.save() and QPainter.restore(), so that pen and brush colors intended for one square don't propagate to others.

Figure 11.8 The Counters custom widget

Include an if _name_ == "_main_": statement at the end, and create a

QApplication object and an instance of the Counters widget so that you can test it. The whole thing can be done in less than 130 lines.

A solution is given in chap11/counters.py.

This page intentionally left blank

• Animation and Complex Shapes

Was this article helpful?

0 0


The main focus of this report is to show how to get involved in video marketing on the run, how to rank quickly on YouTube and Google using FREE semi-automatic tools and services. QUICKLY AND FREE. I will show methods and techniques I use to rank my videos, as well as free resources and tools to make video clips, to get backlinks and free traffic.

Get My Free Ebook

Post a comment