QGIS API Documentation 4.1.0-Master (bf6e22d825e)
Loading...
Searching...
No Matches
qgspersistentmenu.cpp
Go to the documentation of this file.
1/***************************************************************************
2 QgsPersistentMenu.cpp - menu to be used in toolbar
3 ---------------------
4 begin : June 2026
5 copyright : (C) 2026 by Till Frankenbach
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#include "qgspersistentmenu.h"
17
18#include <QAction>
19#include <QMouseEvent>
20#include <QSignalBlocker>
21
22#include "moc_qgspersistentmenu.cpp"
23
24QgsPersistentMenu::QgsPersistentMenu( const QString &title, QWidget *parent )
25 : QMenu( title, parent )
26{}
27
30
32{
33 QAction *action = activeAction();
34 if ( action && action->isEnabled() )
35 {
36 action->trigger();
37 e->accept();
38 }
39 else
40 QMenu::mouseReleaseEvent( e );
41}
42
44{
45 if ( e->key() == Qt::Key_Return || e->key() == Qt::Key_Enter || e->key() == Qt::Key_Space )
46 {
47 QAction *action = activeAction();
48 if ( action && action->isEnabled() )
49 {
50 action->trigger();
51 e->accept();
52 return;
53 }
54 }
55 else
56 QMenu::keyPressEvent( e );
57}
void keyPressEvent(QKeyEvent *e) override
QgsPersistentMenu(const QString &title, QWidget *parent=nullptr)
QgsPersistentMenu is a menu to be used with toolbars.
void mouseReleaseEvent(QMouseEvent *e) override