PDA

View Full Version : Designing a QGraphics view framework application



regular
9th May 2013, 16:55
Hi, I have a code design question.

When creating an application with QGraphicsView and QGraphicsScene, is it bad design to let the scene handle user interface issues (like opening QDialogs or QWizards) and handle mouse events? In my case I need the user to specify some properties of QGraphicsItems before creating them by filling in a QWizard and later modify these properties by using a QDialog - where should this be handled?

Also, in the Diagram scene example (http://qt-project.org/doc/qt-4.8/graphicsview-diagramscene.html) for the QGraphics view framework, the QGraphicsItem context menus are all handled by the QMainWindow - is this a good approach?

What if I want a double click on a QGraphicsItem to open a dialog? Would the item need to know about dialogs?

Any other tips when designing such an application?

Thanks in advance.

Santosh Reddy
10th May 2013, 14:11
When creating an application with QGraphicsView and QGraphicsScene, is it bad design to let the scene handle user interface issues (like opening QDialogs or QWizards) and handle mouse events? In my case I need the user to specify some properties of QGraphicsItems before creating them by filling in a QWizard and later modify these properties by using a QDialog - where should this be handled?
QGraphicsScene handing mouse evetns is still ok, but defenetly should not handle QDialogs/QWizards. The better way is to educate the QDialogs/QWizards about the interface which QGraphicsScene/QGraphicsItems will provied. Here is an example of simple workflow.

1. User double-clicks a QGraphicsItem (with and intention to edit it's custom properties)
2. QGrpahcisScene gets the mouse event and then emits a signal (say itemEditTriggered(QGraphicsItem *))
3. This signal is connected to a slot in the custom QDialog/QWizard, which knows how to read the QGraphicsItem interface, and edit it if required.


Also, in the Diagram scene example for the QGraphics view framework, the QGraphicsItem context menus are all handled by the QMainWindow - is this a good approach?
I will say it is somewhat ok, if is limited to context menus, but if you want high features like QWizards, and QDialogs, I don't see that as a good approach.


What if I want a double click on a QGraphicsItem to open a dialog? Would the item need to know about dialogs?
No, as it said, it better be other way round, let the dialog know about the item.

regular
10th May 2013, 14:30
Thank you for the tips. Sending signals from the QGraphicsItems sounds like a better approach.

So if I need to open a QWizardDialog when the user clicks the scene, maybe I should send a signal from the scene's event handler and connect that signal to a slot on the QWizard itself (or maybe the QMainWindow or QGraphicsView)?

Thanks again.