PDA

View Full Version : I need advise about working with a QGraphicsScene and QGraphicsview



ayanda83
3rd April 2015, 17:44
Okay guys I am developing an Ms Publisher-like application which will be used primarily for designing 4-page pamphlets. Each pamphlet page is of A5 size. My approach to developing this application is through the use of a QGraphicsView and QGraphicsScene but now I don't know if I need four scenes for each page or if I can use one scene and just sub-divide it four times. If I subdivide the scene 4 times I need to view to display one subdivision at a time to allow the user to work on one page at a time. Problem is, I don't know if that is possible. Your advise will be highly appreciated.

thanking you in advance.

d_stranz
3rd April 2015, 18:42
If you use the Graphics / View architecture, you can put all four pages as separate graphics items in the same scene. Since all of your views will presumably be of the same document, then you need only one scene. Which part of the scene you display is determined by the viewport you set in each view QGraphicsView::setSceneRect(). By changing the position of the individual items within the scene, you can choose whether to display the pages side-by-side or in a 2 x 2 array, etc.. You might even add drag and drop capability to let the user change the order of pages.

If you are using the A-sized paper system as the units for your scene, then you would want to set the scene dimensions to be some multiple of A5 pages wide x high, multiplied by some reasonable dimension in print resolution (eg. 2 x A5 width in mm x 12 pixels / mm by 2 x A5 height x 12 for a 2x2 page scene).

Alternatively, doing this without Graphics / View, your main UI would contain a QStackedWidget, with one page image per page in the stack, and maybe a 5th page to show the entire document. Each page in the stack is responsible for the editing of the image in that page, and your document keeps track of the order of the pages. Or use a QTabWidget, with one image per tab and a 5th tab for the document view. Let the user rearrange the tabs to change the page order.

Or, you can use QGraphicsScene and the same stacked widget, each page containing a QGraphicsView dedicated to the scene rect for one page of the document.

In any case, you will have to provide the same kind of tools for editing and manipulating the page and document content. If you choose to implement the output of those tools as individually editable graphical elements (eg. text, geometric objects, lines, and groups of them), then the Graphics / View architecture is probably the best choice, since it has built-in support for all of that.

ayanda83
4th April 2015, 18:32
@d_stranz, thank you very much for taking the time to answer my question. Your reply was very informative, it helped me a lot. thank you.