Enhance the Page Designer application by adding a new button, Align, which has a pop-up menu of Align Left, Align Right, Align Top, and Align Bottom. Provide a single method, setAlignment(), that takes an alignment argument. Be sure to keep an instance variable with the wrappers so they don't get garbage-collected. To perform the alignment there must be at least two items selected (because items are aligned with respect to each other).

The algorithm in the solution has two phases: First it finds the item to align every other item in relation to; for example, if doing Align Left, it finds the leftmost item. Note that this must be done in terms of the sceneBoundingRect(), not the boundingRect() (which is different if the item is rotated). Second, it works out the x or y difference to be applied to the other items and then applies it. Adding the extra button and its menu will take less than 15 lines of code, and setAlignment() can be written in less than 45 lines, so the whole thing can be done in about 60 lines.

A solution is provided in chap12/pagedesigner_ans.pyw.

• Rich Text Editing

• Printing Documents

Was this article helpful?

+1 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