Results 1 to 4 of 4

Thread: Making QMouseEvent only triggered by MousePress and ignore move and release

  1. #1
    Join Date
    Sep 2017
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question Making QMouseEvent only triggered by MousePress and ignore move and release

    I am using a function called InstallEventHandler which takes the name of the event and install handler to it

    installEventHandler("QWidget", "QMouseEvent","mouse_event")

    in which the QWidget is the type the the event handler is installed to, the QMouseEvent is the event that causes the handler to be called, and the mouse_event is the handler.

    I want the function to be triggered when mouse is pressed only but I am encountered with a problem that the QMouseEvent is generated with mouse moves and releases too not only QMousePressEvent. Which make the fuction gets called thousands of times and misses my code.

    I am trying since days to find a way and searching all the available methods but non is working.
    Last edited by mohatem; 18th September 2017 at 23:33.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Making QMouseEvent only triggered by MousePress and ignore move and release

    Modify your method so it takes a 4th argument of QEvent::Type. For the case you describe above, that would be QEvent::MouseButtonPress. Inside your method, you check to see that pEvent->type() == QEvent::MouseButtonPress, and if it is, you call the event handler.

    Qt Code:
    1. installEventHandler( "QWidget", "QMouseEvent", QEvent::Type eventType, "mouse_event" );
    To copy to clipboard, switch view to plain text mode 

    Alternatively, modify your event handler so it takes the QEvent pointer:

    Qt Code:
    1. void eventHandler( QWidget * sender, QEvent * pEvent );
    To copy to clipboard, switch view to plain text mode 

    and inside your event handler you can choose to act only if the event type is MouseButtonPress.

    I am not really sure why you are trying to reinvent this wheel. Qt already has the capability to install an event handler on any QObject. See QObject::installEventFilter().
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Sep 2017
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Making QMouseEvent only triggered by MousePress and ignore move and release

    The problem is that I don't have access to the function, it's created by "squish" and I am only using it.
    I tried to use qt QObject::installEventFilter, but I am encountered with the problem that install event filter must take the object I want to Install the filter to.

    While here it takes the type "QWidget" which is everything and install the filter to them even the dynamically created widgets during runtime.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,243
    Thanks
    303
    Thanked 866 Times in 853 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Making QMouseEvent only triggered by MousePress and ignore move and release

    I see. Is there a "squish" users forum? You might get more help there by people familiar with it.

    What gets sent to your "mouse_event" callback function? If there is a pointer to the event itself, you can still use the event type to select out the ones you want.

    Which make the function gets called thousands of times and misses my code.
    I do not know what you mean by "misses my code". The "mouse_event" function is something you have written, right?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 0
    Last Post: 22nd July 2014, 22:36
  2. Replies: 0
    Last Post: 18th June 2013, 11:54
  3. Replies: 0
    Last Post: 11th January 2011, 13:31
  4. Replies: 3
    Last Post: 28th September 2010, 11:48
  5. Make QDial ignore user input
    By burnchar in forum Qt Programming
    Replies: 4
    Last Post: 17th February 2010, 19:52

Tags for this Thread

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.