Results 1 to 7 of 7

Thread: QEvent::Enter

  1. #1
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default QEvent::Enter

    I try with no success to activate a slot when the mouse enters a widget's boundary.
    Once activated I would like to change the cursor shape (hope i find that by myself!!)

    This, below, does not do anything. I thought when hovering over the widget the window would close as a proof the event occured.

    Qt Code:
    1. connect( pbDestin, SIGNAL( QEvent::Enter ), this, SLOT( close() ) );
    To copy to clipboard, switch view to plain text mode 

    But it does not close the window...

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QEvent::Enter

    Events are not signals. You must reimplement QWidget::enterEvent() or use event filter.

  3. The following user says thank you to jacek for this useful post:

    incapacitant (21st March 2006)

  4. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QEvent::Enter

    There is a difference between events and signals/slots. You should study these concepts a bit:
    Signals and Slots
    Events and Event Filters

    You can connect signals to slots, but for catching events you need to subclass or use an event filter.

  5. The following user says thank you to jpn for this useful post:

    incapacitant (21st March 2006)

  6. #4
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QEvent::Enter

    Following your good advice, I set up an event filter that works. I was just wondering whether there is a better way than what I implemented.

    For each Widget that I want to react to QEvent::Enter or QEvent::Leave I added :
    Qt Code:
    1. anyWidget->installEventFilter( this );
    To copy to clipboard, switch view to plain text mode 

    Then as filter :
    Qt Code:
    1. bool ApplicationWindow::eventFilter(QObject *target, QEvent *event)
    2. {
    3. if (event->type() == QEvent::Enter)
    4. QApplication::setOverrideCursor( QCursor(Qt::PointingHandCursor) );
    5. if (event->type() == QEvent::Leave )
    6. QApplication::restoreOverrideCursor();
    7.  
    8. return QMainWindow::eventFilter(target, event);
    9. }
    To copy to clipboard, switch view to plain text mode 


    Is this the right way to do it ?

  7. #5
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: QEvent::Enter

    Its your choice..but you also can use next way

    Qt Code:
    1. ///// *.h
    2.  
    3. protected:
    4. void enterEvent(QEvent*ev);
    5. void leaveEvent(QEvent*ev);
    6.  
    7. //// *.cpp
    8.  
    9. void ApplicationWindow::enterEvent(QEvent*ev)
    10. {
    11. QApplication::setOverrideCursor( QCursor(Qt::PointingHandCursor) );
    12. }
    13. void ApplicationWindow::leaveEvent(QEvent*ev)
    14. {
    15. QApplication::restoreOverrideCursor();
    16. }
    To copy to clipboard, switch view to plain text mode 
    a life without programming is like an empty bottle

  8. The following user says thank you to zlatko for this useful post:

    incapacitant (22nd March 2006)

  9. #6
    Join Date
    Jan 2006
    Location
    Grenoble, France
    Posts
    165
    Thanks
    106
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QEvent::Enter

    hi,

    I tried this other method you propose but it does not work for me. The following happens, the events are triggered as soon as the cursor enters the application window and not for the buttons only. Maybe this is because of QT4.

  10. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QEvent::Enter

    Quote Originally Posted by incapacitant
    the events are triggered as soon as the cursor enters the application window and not for the buttons only.
    By this approach you would need to subclass the buttons to get their enter and leave events.
    If you subclass the main window, you'll get the enter and leave events for the main window.
    By using an event filter you are able to catch events going to buttons without subclassing them.

  11. The following user says thank you to jpn for this useful post:

    incapacitant (22nd March 2006)

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.