Results 1 to 5 of 5

Thread: making QGraphicsItemGroup inherit from QObject

  1. #1
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default making QGraphicsItemGroup inherit from QObject

    For some reason QGraphicsItemGroup doesn't inherit from QObject. It creates special handling for this class objects, when making these objects scriptable and has become a nuisance for me . I would like to subclass QGraphicsItemGroup so that it inherits from QObject and QGraphicsItemGroup. However that is easier said than done when looking at the implementation of QGraphicsObject ;( .
    So I have two ways
    1. Subclass QGraphicsItemGroup to inherit from QObject and QGraphicsItemGroup and re-implement along the lines as is done in QGrapicsObject
    2. Forget about QGraphicsItemGroup, Subclass from QGraphicsObject and re-implement all the functionality of QGraphicsItemGroup so that the class behaves like QGraphicsItemGroup but is also a Qobject.
    Which is the easier way. And how do I go ahead about it?

  2. The following 2 users say thank you to pkj for this useful post:

    louboutinoutlet (1st December 2013)

  3. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: making QGraphicsItemGroup inherit from QObject

    QGraphicsItemGroup doesn't inherit from QObject to keep it »light«.
    And what is wrong with:
    Qt Code:
    1. class MyItemGroup : public QObject, public QGraphicsItemGroup
    2. {
    3. Q_OBJECT
    4. public:
    5. MyItemGroup(QGraphicsItem * parent = 0) : QObject(0), QGraphicsItemGroup(parent) {}
    6. // and here use signal and slots as usual
    7. };
    To copy to clipboard, switch view to plain text mode 
    What do you want to recode as it is done in QGraphicsObject?

  4. #3
    Join Date
    Feb 2011
    Location
    Bangalore
    Posts
    207
    Thanks
    20
    Thanked 28 Times in 27 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: making QGraphicsItemGroup inherit from QObject

    I had done that. But going through the large QGraphicsObject's massive code is making me nervous about some possible hacks in QGraphicsObject class to make it work as a QObject. Although I have got it working with expected behavior(in the way you told) I will hate to go through all the testing to find it can't work. I hope you understand my nervousness

  5. #4
    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: making QGraphicsItemGroup inherit from QObject

    There are no hacks there. The only thing QGraphicsObject does more compared to QGraphicsItem is that it has a bunch of properties available. If you don't need them, you don't need to write any additional code.
    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.


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

    pkj (13th September 2011)

  7. #5
    Join Date
    Aug 2011
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: making QGraphicsItemGroup inherit from QObject

    I face the same need as the author of this thread. Of course, that's great to have lighter QGraphicsItem when you do not need QObject functionality. The same goes for QGraphicsItemGroup. Anyway, when you do need QObject features for group of items, it would be great to have one or, at least, be able to get one without much fuzz. I though about inheriting my group from QGraphicsObject and QGraphicsItemGroup (much like QGraphicsObject inherits QObject and QGraphicsItem). Both are based on QGraphicsItem, and it seems that this solution would work if either QGraphicsObject or QGraphicsItemGroup inherit QGraphicsItem virtually. Thus, we could get a class with group management and QGraphicsObject features enabled. Does anybody aware of any troubles with such approach?

Similar Threads

  1. QGraphicsItem doesn't inherit QObject?
    By xyzt in forum Qt Programming
    Replies: 6
    Last Post: 26th September 2011, 14:59
  2. About inherit
    By nesson in forum Qt Programming
    Replies: 1
    Last Post: 8th February 2011, 13:07
  3. QTreeWidgetItem does not inherit QObject
    By johnmauer in forum Qt Programming
    Replies: 2
    Last Post: 20th January 2010, 15:35
  4. Making them all QObject's - good or bad practive?
    By andre in forum Qt Programming
    Replies: 3
    Last Post: 2nd November 2009, 19:00
  5. Inherit from QObject for data-classes?
    By niko in forum Qt Programming
    Replies: 7
    Last Post: 14th July 2007, 15:09

Tags for this Thread

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.