Results 1 to 5 of 5

Thread: access to event when an object is dinamically created

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default access to event when an object is dinamically created

    Hi,

    it's strange, but I have a very basic question but I don't find the answer :S

    if you create something, like for instance:

    Qt Code:
    To copy to clipboard, switch view to plain text mode 

    How I can access to its events? In my case, I would like to execute code when painting is called, so far I've subclased the paint event but for the first time I'm not subclassing anything.

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: access to event when an object is dinamically created

    You have two options:
    1. Subclass QGraphicsPixmapItem and override the event methods you want
    2. Install an event filter on the object - see http://doc.trolltech.com/4.6/qobject...allEventFilter on how to do it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: access to event when an object is dinamically created

    thanks! that was what I was searching for.

  4. #4
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Re: access to event when an object is dinamically created

    uop, sorry, I just have seen now that a QGraphicsItem is not a QObject, so install the event filter is not allowed.

    the only thing I see is QGraphicsItem::installSceneEventFilter, but I need to filter the events of one QGraphicsPixmapItem in one QObject, not one graphics item into another.

    Am I wrong? or do I have any other possibility than subclass?

  5. #5
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: access to event when an object is dinamically created

    Sorry, I forgot that QGrphicsItems are not QObjects.
    I think the easiest way would be to subclass QGraphicsPixmapItem and deal with the events there.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. How to access Widgets created in Tab View
    By kapoorsudhish in forum Newbie
    Replies: 5
    Last Post: 23rd October 2009, 13:12
  2. Replies: 2
    Last Post: 20th September 2009, 02:52
  3. How to access an object inside a privateslot
    By graciano in forum Qt Programming
    Replies: 7
    Last Post: 21st January 2009, 18:09
  4. Access an object stored in the list.
    By cbarmpar in forum General Programming
    Replies: 2
    Last Post: 21st September 2008, 20:19
  5. Access an object from another file.
    By cbarmpar in forum General Programming
    Replies: 1
    Last Post: 6th September 2008, 22:17

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.