Results 1 to 4 of 4

Thread: QGraphicsItem and signals

  1. #1
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QGraphicsItem and signals

    I have a silly problem...
    i just wanted to know what item was selected from the scene. For this I tried using signal from the class(derived from QGraphicsItem) but seems I cannot add signals to the subclass I also tried remaking the .pro but of no use.

    I would like to know if we can emot signals from a class derived from QGraphicsItem or not ?

    I know the other method around for this prob... get the items on mouse press and get the required item , but was just curious for the question above

  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 signals

    Quote Originally Posted by aamer4yu View Post
    i just wanted to know what item was selected from the scene. For this I tried using signal from the class(derived from QGraphicsItem) but seems I cannot add signals to the subclass
    You can, just inherit from both QObject and QGraphicsItem and make sure QObject is mentioned first in the inheritance list. And remember about the Q_OBJECT macro.

    I would like to know if we can emot signals from a class derived from QGraphicsItem or not ?
    Yes, if you also inherit QObject

    I know the other method around for this prob... get the items on mouse press and get the required item , but was just curious for the question above
    How about just using QGraphicsScene::selectedItems()?

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsItem and signals

    Thanks...

    How about just using QGraphicsScene::selectedItems()?
    Well I am not selecting the items based on rubberbanding... just need to pick item from mouse press... so i guess items() will also do isnt it ?

  4. #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 and signals

    Quote Originally Posted by aamer4yu View Post
    Well I am not selecting the items based on rubberbanding... just need to pick item from mouse press... so i guess items() will also do isnt it ?
    Yes, but is it worth it? I'd simply make items selectable using QGraphicsItem::ItemIsSelectable and then query for items selected - you'll get a much shorter list resulting in a faster application. But maybe you can simply use QGraphicsItem::mousePressEvent() and handle the interaction there? It would be best this way... There is no need to call either items(), selectedItems() nor a mouse press from the scene then.

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.