Results 1 to 7 of 7

Thread: QGraphicsItem doesn't inherit QObject?

  1. #1
    Join Date
    Mar 2008
    Posts
    15
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsItem doesn't inherit QObject?

    in the documentation there's a sample that inherits both QObject and QGraphicsItem. Deoesn't QGraphicsItem inherits QObject? I looked at the Qt Assistant but it doesn't give info about that.

    Qt Code:
    1. class Mouse : public QObject, public QGraphicsItem
    2. {
    3. Q_OBJECT
    4.  
    5. public:
    6. Mouse();
    7.  
    8. QRectF boundingRect() const;
    9. QPainterPath shape() const;
    10. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
    11. QWidget *widget);
    12.  
    13. protected:
    14. void timerEvent(QTimerEvent *event);
    15.  
    16. private:
    17. qreal angle;
    18. qreal speed;
    19. qreal mouseEyeDirection;
    20. QColor color;
    21. };
    To copy to clipboard, switch view to plain text mode 

  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 doesn't inherit QObject?

    No, QGraphicsItem doesn't inherit QObject. It would be too heavy then.

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

    xyzt (22nd March 2008)

  4. #3
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem doesn't inherit QObject?

    And what about signals and slots? How we can emit signals and connect them to slots?
    Standard QObject::connect will not work. At least it doesn't work in my project, when I try to send the signal from the item to QWidget(every time I've got doesn't match -error).

  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: QGraphicsItem doesn't inherit QObject?

    Signals and slots require QObject legacy. You can use QGraphicsObject for custom items or subclass existing graphics item classes and derive them from QObject as well.
    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:

    DmitryNik (26th September 2011)

  7. #5
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem doesn't inherit QObject?

    Thank you. I guess, it's only way for getting signals and doing the project in a right way.

  8. #6
    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 doesn't inherit QObject?

    No, it's not the only way. You can have a separate controller object that will emit signals on behalf of your items. Then you don't have to modify the item classes and they will remain to be light as you'll only have one object that emits signals for all your items.
    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.


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

    ajo (6th December 2012), DmitryNik (26th September 2011)

  10. #7
    Join Date
    Sep 2011
    Posts
    45
    Thanks
    17
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem doesn't inherit QObject?

    Oh, I didn't consider that at all. Thank you once again for helping. I need to try your advice.

Similar Threads

  1. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 11:31
  2. Inherit from QObject for data-classes?
    By niko in forum Qt Programming
    Replies: 7
    Last Post: 14th July 2007, 16:09

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.