Results 1 to 15 of 15

Thread: Mouseover signal on QAction

  1. #1
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Mouseover signal on QAction

    Hi all !
    Can you help me?
    I would like get Signal (or Event ) when mouse Over QAction. QAction doesn't is QWidget and doesn't have method mouseMoveEvent ( QMouseEvent * ),...

    I use Qt4.0 (on MacOS X and Windows ).

  2. #2
    Join Date
    Feb 2006
    Location
    Roma ( Italy )
    Posts
    7
    Thanks
    3
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Mouseover signal on QAction

    Hi,
    you can try to derive your class to QAction and QWidget, for example:

    class myClass : public QAction, public QWidget {
    // some code
    }

    Bye

  3. #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: Mouseover signal on QAction

    This works at least for menu items (not for toolbar buttons as I recall):
    QAction::hovered() [signal]

    Mouse move events occur only if a mouse button is pressed (unless mouse tracking is on).
    So I guess you're interested of enter and leave events..

    For toolbar buttons, you could install an event filter and catch all enter and leave events.

  4. #4
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Yes, it is my problem. I would like Signal MouseOver on QAction when QAction on QToolBar.
    Can you help me !

  5. #5
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Quote Originally Posted by jpn
    This works at least for menu items (not for toolbar buttons as I recall):
    QAction::hovered() [signal]

    Mouse move events occur only if a mouse button is pressed (unless mouse tracking is on).
    So I guess you're interested of enter and leave events..

    For toolbar buttons, you could install an event filter and catch all enter and leave events.
    Could you example code for me because I don't understand that( installEventFilter )

  6. #6
    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: Mouseover signal on QAction

    Do you use Qt3 or Qt4, and did you add the action to the toolbar in designer or in code?

  7. #7
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Quote Originally Posted by jpn
    Do you use Qt3 or Qt4, and did you add the action to the toolbar in designer or in code?
    I used Qt4.0 and I add the action in code.
    QToolBar,QAction,... I rebuilded my class in my App.

  8. #8
    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: Mouseover signal on QAction

    You could install an even filter for all widgets in the toolbar like this:
    (eg. in the constructor of your main window, after adding actions to the toolbar)
    Qt Code:
    1. QList<QWidget*> widgets = toolbar->findChildren<QWidget*>();
    2. foreach (QWidget* widget, widgets)
    3. widget->installEventFilter(this);
    To copy to clipboard, switch view to plain text mode 

    And here's a skeleton for the event filter:
    Qt Code:
    1. bool MainWindow::eventFilter(QObject* obj, QEvent* e)
    2. {
    3. if (e->type() == QEvent::Enter)
    4. {
    5. // a widget in the toolbar was entered
    6. // you may cast obj to a widget and do sth with it here
    7. }
    8. else if (e->type() == QEvent::Leave)
    9. {
    10. // a widget in the toolbar was left
    11. }
    12. return QMainWindow::eventFilter(obj, e);
    13. }
    To copy to clipboard, switch view to plain text mode 

    PS. it could have been useful information to know, what are you exactly trying to do when mouse is over an toolbar action?

  9. #9
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Quote Originally Posted by jpn
    PS. it could have been useful information to know, what are you exactly trying to do when mouse is over an toolbar action?
    Example I change Icon of Action when Mouse Over Action, and i can dosomthing it, or I can emit Signal for other Dev use, ect,..
    thank you very much !
    PS: my English is very bad ?

  10. #10
    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: Mouseover signal on QAction

    Quote Originally Posted by manhds
    Example I change Icon of Action when Mouse Over Action
    For the changing icon, you can construct a QIcon with separate pixmaps for normal, disabled and active modes, and then just set the icon for the action.
    Qt Code:
    1. QIcon icon;
    2. icon.addPixmap(QPixmap("normal.png"), QIcon::Normal);
    3. icon.addPixmap(QPixmap("disabled.png"), QIcon::Disabled);
    4. icon.addPixmap(QPixmap("active.png"), QIcon::Active);
    5. action->setIcon(icon);
    To copy to clipboard, switch view to plain text mode 

  11. #11
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Quote Originally Posted by jpn
    For the changing icon, you can construct a QIcon with separate pixmaps for normal, disabled and active modes, and then just set the icon for the action.
    Qt Code:
    1. QIcon icon;
    2. icon.addPixmap(QPixmap("normal.png"), QIcon::Normal);
    3. icon.addPixmap(QPixmap("disabled.png"), QIcon::Disabled);
    4. icon.addPixmap(QPixmap("active.png"), QIcon::Active);
    5. action->setIcon(icon);
    To copy to clipboard, switch view to plain text mode 
    Thanks, this is very good with Change Icon, but I would like other process when Mousever !

  12. #12
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Hi jpn !
    I used installEventFilter but I don't get event mouseover with QAction on QToolbar. Maybe I wrong it

  13. #13
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    thanks and see you again tomorrow.
    Now, I must go out the Office.

  14. #14
    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: Mouseover signal on QAction

    Quote Originally Posted by manhds
    I used installEventFilter but I don't get event mouseover with QAction on QToolbar.
    How did you install the event filter?
    - You must install the event filter for the button in the toolbar, not for the action..

    Which event type are you catching? What is "event mouseover"?
    - As I mentioned earlier, mouse move events occur only if a mouse button is pressed (unless mouse tracking is on). So use enter and leave events.

  15. #15
    Join Date
    Jan 2006
    Location
    ha noi - viet nam
    Posts
    24
    Thanks
    1
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Mouseover signal on QAction

    Quote Originally Posted by jpn
    How did you install the event filter?
    - You must install the event filter for the button in the toolbar, not for the action..

    Which event type are you catching? What is "event mouseover"?
    - As I mentioned earlier, mouse move events occur only if a mouse button is pressed (unless mouse tracking is on). So use enter and leave events.
    Yes, I do it Success !
    Because Yesterday I doesn't install the event filter for the button in the toolbar.
    Thanks jpn !

Similar Threads

  1. pthread instead QThread
    By brevleq in forum Qt Programming
    Replies: 8
    Last Post: 23rd December 2008, 07:16
  2. Connection of custon signals/slots
    By brevleq in forum Qt Programming
    Replies: 2
    Last Post: 23rd December 2008, 07:04
  3. Having some QObject problems
    By Barvik in forum Qt Programming
    Replies: 7
    Last Post: 13th November 2008, 04:29
  4. QAction signal: want to send int
    By vonCZ in forum Newbie
    Replies: 10
    Last Post: 2nd July 2007, 18:52

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.