Results 1 to 3 of 3

Thread: QGraphicsItem and Context Menus

  1. #1
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default QGraphicsItem and Context Menus

    I'm implementing a QGraphicsItem class. I would like the user to right-click over an object of this class and interact with a context menu, selecting an item that the object will then use to adjust it's iternal state.

    Getting the menu to popup is simple, but I'm not sure how to make use of it. I could inherit from QObject and simply implement signals and slots, but there is a potential for a few tens of thousands of these objects to exist at any given time, and QObject is pretty heavy.

    The documentation for QGraphicsItem trails off just after menu setup, without actually providing a solution to this problem.

    I'll be calling exec() to show the menu synchronously. Should I just examine the menu contents upon return, or use a QActionGroup in a similar fashion? Or is there a better way to do this?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsItem and Context Menus

    Menu actions can be connected to slots in the scene and the scene can "call back" to the active item or something like that. You don't need signals and slots in the item in such situation if that's causing you a headache here
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem and Context Menus

    I thought about connecting them all to a centralized QObject of some sort. I may still do that, but it looks like all of the possible menu choices will become members of a QActionGroup, which I can examine when the exec() call returns to determine which item was checked. In our case, that's a "cleaner" solution if it will work. Done coding for the day, but I'll do a quick test tomorrow.

Similar Threads

  1. Replies: 1
    Last Post: 10th December 2010, 07:10
  2. Context Menus
    By qtoptus in forum Newbie
    Replies: 0
    Last Post: 25th June 2010, 16:18
  3. Context Menus
    By rodlbr in forum Qt Programming
    Replies: 4
    Last Post: 7th September 2009, 17:30
  4. Multiple Context Menus
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 24th December 2008, 20:55
  5. Replies: 0
    Last Post: 21st March 2008, 22:34

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.