Results 1 to 3 of 3

Thread: Designing a QGraphics view framework application

  1. #1
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Designing a QGraphics view framework application

    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 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.

  2. The following user says thank you to regular for this useful post:


  3. #2
    Join Date
    Mar 2011
    Location
    Hyderabad, India
    Posts
    1,882
    Thanks
    3
    Thanked 452 Times in 435 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows
    Wiki edits
    15

    Default Re: Designing a QGraphics view framework application

    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.
    When you know how to do it then you may do it wrong.
    When you don't know how to do it then it is not that you may do it wrong but you may not do it right.

  4. The following user says thank you to Santosh Reddy for this useful post:


  5. #3
    Join Date
    Apr 2013
    Posts
    14
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Designing a QGraphics view framework application

    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.

  6. The following user says thank you to regular for this useful post:


Similar Threads

  1. To any Qgraphics framework guru... need a solution...
    By tonnot in forum Qt Programming
    Replies: 4
    Last Post: 30th November 2011, 09:31
  2. Creating Qgraphics View code
    By amagdy.ibrahim in forum Qt Programming
    Replies: 9
    Last Post: 15th June 2008, 16:43
  3. Qgraphics View
    By amagdy.ibrahim in forum Qt Programming
    Replies: 1
    Last Post: 15th June 2008, 11:10
  4. QGraphics view update : Help needed
    By kiranraj in forum Qt Programming
    Replies: 3
    Last Post: 3rd July 2007, 13:54
  5. QGraphics view problem
    By kiranraj in forum Qt Programming
    Replies: 5
    Last Post: 6th March 2007, 22:28

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.