PDA

View Full Version : click on menubar item (without submenu actions)



navid
8th December 2009, 09:53
Hi

how can I catch left click on menubar item (without submenu actions) in mainwindow?
I want to view dockwidgets and toolbar list popup (such as when you do rigth click on menubar / toolbar), when there is left click on a menubar item (with name &view).

regards
navid

yogeshgokul
8th December 2009, 10:01
Hi

how can I catch left click on menubar item (without submenu actions) in mainwindow?
I want to view dockwidgets and toolbar list popup (such as when you do rigth click on menubar / toolbar), when there is left click on a menubar item (with name &view).

regards
navid
Install event filters.

navid
8th December 2009, 17:33
source code (from help of Qt4.6) is


protected:
bool eventFilter(QObject *obj, QEvent *ev);

MainWindow::MainWindow()
{
ui->menuBar->installEventFilter(this);
}

bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (obj == ui->menuBar) {
if (event->type() == QEvent::MouseButtonPress) {
QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
qDebug() << "key pressed" << keyEvent->key();
return true;
} else {
return false;
}
} else {
// pass the event on to the parent class
return QMainWindow::eventFilter(obj, event);
}
}

but for each time of click on the same menubar item, i receive a new number or receive the same number for different menubar items:

Ate key press 9
Ate key press 7
Ate key press 7
Ate key press 8
Ate key press 8
Ate key press 11
Ate key press 10
Ate key press 9
Ate key press 9
Ate key press 10
Ate key press 10
Ate key press 10
Ate key press 10
Ate key press 10
Ate key press 10
Ate key press 9
Ate key press 9
Ate key press 9
Ate key press 9
Ate key press 6
Ate key press 6
Ate key press 6

what is the solution?