A QToolButton is a QAbstractButton, it has a QAbstractButton::pressed() and QAbstractButton::released() signal.
Cheers,
_
A QToolButton is a QAbstractButton, it has a QAbstractButton::pressed() and QAbstractButton::released() signal.
Cheers,
_
Hi Guys and thanks for your replies...
I have made some progress with the event filter...
If I do this in mainwindow.cpp
FilterObject FO;
ui->mainToolBar->installEventFilter(&FO);
and then in FilterObject
bool FilterObject::eventFilter(QObject *object, QEvent *event)
{
if (event->type() == QEvent::MouseButtonPress) {
qDebug() << "Mouse Press On Toolbar";
return true;
}
return false;
}
I can detect the mouse press on the toolbar which is great.
However when I try to detect the mouse pressed from a button / action on the toolbar it no longer works
I replace ui->mainToolBar->installEventFilter(&FO); with ui->actionDoWork->installEventFilter(&FO);
The action DoWork is a button generated by the Action Editor.
So basically it works to detect mouse events on the toolbar but not from an action button on the toolbar.
What I really need is to read the mouse events from the buttons on the toolbar.
Again, thanks and any ideas / hints are welcome.
Regards,
Louis
Why do you use an event filter?
What is the reason you are not using the signals of the button?
Cheers,
_
irish_guy@hotmail.com (10th September 2015)
Thanks Anda,
I used the event filter because I was unable to figure out how to use these signals of the button on a toolbar.
I can use the signals from a normal push button but I can't understand how to get the same signals from the toolbar buttons.
Is there any example of using the QAbstractButton in this way or a similar way?
I am new to this so sorry if it is obvious....
Thanks Again,
Louis
There is no difference. The signal/slot mechanism works the same way for all QObject subclasses
With SIGNAL/SLOT macros:
The circumstance that the button is on a toolbar doesn't change anything, connect() doesn't even care that the sender is a QWidget derived class.Qt Code:
connect(pointerToToolButton, SIGNAL(pressed()), pointerToReceiver, SLOT(someSlotNameHandlingPress()));To copy to clipboard, switch view to plain text mode
Cheers,
_
Thanks again & Almost there I think...
When I try to connect the signals and slots... I get a run time message that there is No such Signal QAction:ressed()
connect(ui->actionZoom_In, SIGNAL(pressed()), this, SLOT(MousePress()));
QObject::connect: No such signal QAction:ressed() in ../CameraControlGUI/mainwindow.cpp:66
QObject::connect: (sender name: 'actionZoom_In')
QObject::connect: (receiver name: 'MainWindow')
When I connect to the 'triggered signal'
connect(ui->actionZoom_In, SIGNAL(triggered()), this, SLOT(MousePress()));
it works fine but I really need pressed and released...
Regards
Louis
Ah, yes, I should have written QToolButton, not QAction.
Oh, wait, I did.
Cheers,
_
Bookmarks