Exercise

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
Tube Jacker

Tube Jacker

Download Tube Jacker And Discover Everything You Need To Know About Jacking Unlimited Traffic From The Video Giant. The drop dead easy way to create winning video campaigns that will FLOOD your website with unstoppable FREE traffic, all on complete and total autopilot. How to exploit a sneaky method of boosting exposure and getting your videos to the top of Google within 72 hours, guaranteed.

Get My Free Ebook


Post a comment