Results 1 to 8 of 8

Thread: sceneEventFilter or eventFilter

  1. #1
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default sceneEventFilter or eventFilter

    Hi,
    I have a QGraphicsItem in which I want to monitor it to catch mouse press event. I could do it by reimplementing mouse press event. But I want to do it in a different way by using event filtering.

    I first tried out eventFilter in my graphics item but the program didn't even enters the eventFilter() fucntion. First of all is that OK?

    Secondly, should I use sceneEventFilter()? Could this method give what I wanna achieve?

    Thanks in advance

  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: sceneEventFilter or eventFilter

    The item has a sceneEventFilter() method not eventFilter(). And you have to install an event filter to use it. But I'd really suggest to use mousePressEvent(). Intercepting events for yourself in the event filter doesn't make much sense. Is there any particular reason why you don't want to implement the functionality in the event handler?
    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. #3
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: sceneEventFilter or eventFilter

    No actually, but I wanted to see how it works. I tried it but I couldn't go in to the following block;

    if( pEvent->type() == QEvent::MousePressEvent)
    {
    // some code
    }

    what's wrong with 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: sceneEventFilter or eventFilter

    Did you install an event filter first? Is there any code we could compile, run and see for ourselves?
    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.


  5. #5
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: sceneEventFilter or eventFilter

    Sure...I installed the scene event filter. but maybe I did it wrongly.

    In my graphics item class, I wrote the following code;

    installSceneEventFilter(this);


    By the way, I'm sorry that I couldn't post you any code since this is prohibited

  6. #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: sceneEventFilter or eventFilter

    I suggest you just forget about this experiment and handle events the regular way. How does your sceneEventFilter() method look like, by the way? Could we at least see its signature?
    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.


  7. #7
    Join Date
    Dec 2008
    Location
    Istanbul, TURKEY
    Posts
    537
    Thanks
    14
    Thanked 13 Times in 13 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: sceneEventFilter or eventFilter

    Qt Code:
    1. void fooItem::sceneEventFilter( QGraphicsItem *pWatched, QEvent* pEvent)
    2. {
    3.  
    4. if( watched == this)
    5. {
    6.  
    7. if( pEvent->type() == QEvent::MousePressEvent)
    8. {
    9. cout<<"item pressed!"<<endl;
    10. return TRUE;
    11. }
    12. else
    13. {
    14. return FALSE;
    15. }
    16.  
    17. }
    18.  
    19. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 4th May 2009 at 07:50. Reason: missing [code] tags

  8. #8
    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: sceneEventFilter or eventFilter

    The method should return bool not void...
    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.


Similar Threads

  1. wheelEvent not working in an eventFilter
    By Cruz in forum Qt Programming
    Replies: 7
    Last Post: 31st January 2009, 23:06
  2. eventFilter in Console App
    By KaptainKarl in forum Newbie
    Replies: 3
    Last Post: 20th December 2008, 00:27
  3. QLineEdit selectAll() in eventFilter
    By mclark in forum Qt Programming
    Replies: 6
    Last Post: 1st February 2008, 08:13
  4. eventFilter: pop-up custom widget
    By vonCZ in forum Newbie
    Replies: 1
    Last Post: 22nd November 2007, 09:54
  5. paintEvent in eventFilter
    By kernel_panic in forum Qt Programming
    Replies: 1
    Last Post: 10th October 2007, 20:59

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.