Results 1 to 4 of 4

Thread: subclassing QGraphicsItem, QGraphicsPixmapItem

  1. #1
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default subclassing QGraphicsItem, QGraphicsPixmapItem

    can someone point me in the right direction to find COMPLETE examples of subclassing. I have not made this request here because i did not want to look like an idiot... but i can not find the docs to show me how to do this.

    Qt Code:
    1. this works for me
    2.  
    3. item=this->scene()->addPixmap(pixmap);
    4.  
    5. i am trying to sub class QGraphicsItem.
    6. my subclass does not work :
    7. myGraphicItem *item;
    8. item=this->scene()->addPixmap(pixmap);
    9.  
    10. error ! cannot convert QGraphicsPixmapItem* to myGraphicsItem* in assignment.
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: subclassing QGraphicsItem, QGraphicsPixmapItem

    It won't work that way. The method returns a QGraphicsPixmapItem so you can only assign it to QGraphicsPixmapItem or its ancesstor (QGraphicsItem) pointer.

    If you want to subclass QGraphicsItem or one of its subclasses, you need to add the item to the scene in a different manner:
    Qt Code:
    1. myGraphicsItem *item = new myGraphicsItem;
    2. scene()->addItem(item);
    To copy to clipboard, switch view to plain text mode 
    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. The following user says thank you to wysota for this useful post:

    rogerholmes (26th August 2009)

  4. #3
    Join Date
    Mar 2009
    Location
    Nashville Tn.
    Posts
    53
    Thanks
    14
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: subclassing QGraphicsItem, QGraphicsPixmapItem

    Thanks Wysota,

    I will try it that way, i need to be able to change the boundingRect. Do you know of a place i can research the subclassing of Qt classes.

    roger

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

    Default Re: subclassing QGraphicsItem, QGraphicsPixmapItem

    Qt is ANSI C++ compliant so everything that applies to subclassing in C++ applies to subclassing Qt classes 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:

    rogerholmes (27th August 2009)

Similar Threads

  1. Replies: 2
    Last Post: 25th March 2011, 10:18
  2. destruction of QGraphicsItem
    By killkolor in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2009, 11:31
  3. Replies: 1
    Last Post: 25th February 2009, 01:34
  4. QGraphicsItem Subclassing
    By QbelcorT in forum Newbie
    Replies: 4
    Last Post: 19th November 2008, 02:06
  5. Multiple Inheritance for QGraphicsItem
    By pankaj.patil in forum Qt Programming
    Replies: 2
    Last Post: 1st July 2008, 15:49

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.