PDA

View Full Version : Mouseover signal on QAction



manhds
20th March 2006, 07:33
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 ).

drow
20th March 2006, 08:35
Hi,
you can try to derive your class to QAction and QWidget, for example:

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

Bye

jpn
20th March 2006, 08:48
This works at least for menu items (not for toolbar buttons as I recall):
QAction::hovered() [signal] (http://doc.trolltech.com/4.0/qaction.html#hovered)

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.

manhds
20th March 2006, 09:10
Yes, it is my problem. I would like Signal MouseOver on QAction when QAction on QToolBar.
Can you help me !

manhds
20th March 2006, 09:22
This works at least for menu items (not for toolbar buttons as I recall):
QAction::hovered() [signal] (http://doc.trolltech.com/4.0/qaction.html#hovered)

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 )

jpn
20th March 2006, 09:24
Do you use Qt3 or Qt4, and did you add the action to the toolbar in designer or in code?

manhds
20th March 2006, 09:37
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.

jpn
20th March 2006, 09:45
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)


QList<QWidget*> widgets = toolbar->findChildren<QWidget*>();
foreach (QWidget* widget, widgets)
widget->installEventFilter(this);


And here's a skeleton for the event filter (http://doc.trolltech.com/4.1/qobject.html#installEventFilter):


bool MainWindow::eventFilter(QObject* obj, QEvent* e)
{
if (e->type() == QEvent::Enter)
{
// a widget in the toolbar was entered
// you may cast obj to a widget and do sth with it here
}
else if (e->type() == QEvent::Leave)
{
// a widget in the toolbar was left
}
return QMainWindow::eventFilter(obj, e);
}


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

manhds
20th March 2006, 10:09
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 ?

jpn
20th March 2006, 10:26
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.


QIcon icon;
icon.addPixmap(QPixmap("normal.png"), QIcon::Normal);
icon.addPixmap(QPixmap("disabled.png"), QIcon::Disabled);
icon.addPixmap(QPixmap("active.png"), QIcon::Active);
action->setIcon(icon);

manhds
20th March 2006, 11:10
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.


QIcon icon;
icon.addPixmap(QPixmap("normal.png"), QIcon::Normal);
icon.addPixmap(QPixmap("disabled.png"), QIcon::Disabled);
icon.addPixmap(QPixmap("active.png"), QIcon::Active);
action->setIcon(icon);


Thanks, this is very good with Change Icon, but I would like other process when Mousever !

manhds
20th March 2006, 11:18
Hi jpn !
I used installEventFilter but I don't get event mouseover with QAction on QToolbar. Maybe I wrong it

manhds
20th March 2006, 11:26
thanks and see you again tomorrow.
Now, I must go out the Office.

jpn
20th March 2006, 12:10
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.

manhds
21st March 2006, 03:24
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 !:)