Results 1 to 3 of 3

Thread: Access to custom widget functions in a QGraphicsScene

  1. #1
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Access to custom widget functions in a QGraphicsScene

    Hello fellow Qt programmers.

    I would like to see if you have any ideas to my problem.

    Here we go. I have a library with custom widgets which I use in my project. I use these widgets in a QGraphicsScene. I add them with the use of QGraphicsProxyWidget. Now to get to the problem. After I have added these widgets i want to access the functions that the initial widget has. ex. my widget has a setValue function.

    And i want to access its functions when ex. you right click on the item in the scene, scene returns the QGraphicsItem with the use of function itemAt. Now I want to cast this QGraphicsItem to the original widget. But this is a problem if I have 20 widgets and I dont know what to cast it to.

    What I am looking for is something similar to the type() functions in QGraphicsItem but for my widget. So I can set a specific type for my widget and i can access it in someway to compare with the QGraphicsItem I get returned.

    Any ideas would be helpful for mapping this in a good way. I have thought of QHash and storing the pointer of the inital widget together the a string key which i also pass for the QGraphicsProxyWidget as data. But this gets messy when you have 20 diffrent widgets.

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

    Default Re: Access to custom widget functions in a QGraphicsScene

    This sounds like a poor design. Create an abstract base class that defines a common interface, then derive all of your QGraphicsItem classes from that interface. Then all items added to a scene will be instances of the same base class and can be treated uniformly. Handle variant behavior at the level of the derived classes.

  3. #3
    Join Date
    Mar 2011
    Posts
    63
    Thanks
    11
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Access to custom widget functions in a QGraphicsScene

    It is a design still in work hence my post here to utilize my design. I dont have any QGraphicsItem classes. The items I add are classes derived from QWidget. But I can see what you mean with the base class.

Similar Threads

  1. Replies: 1
    Last Post: 9th January 2011, 08:20
  2. Replies: 6
    Last Post: 7th December 2010, 13:32
  3. Replies: 2
    Last Post: 7th July 2010, 01:14
  4. Replies: 1
    Last Post: 24th June 2010, 15:50
  5. Passing values to custom 'slot' functions (pyqt)
    By Richie in forum Qt Programming
    Replies: 2
    Last Post: 7th September 2009, 08:05

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.