Menu without action
-
@yogis40 said in Menu without action:
Unfortunately it's not working
What exactly does not work? The connect? ...?
-
It's very unusual for a menu to trigger an action directly, it's more like a button behaviour.
If you want some buttons to trigger actions use a Toolbar, that's what it is made for.Cordialement :)
-
Hi,
As written in the triggered signal documentation:
This signal is emitted when an action in this menu is triggered.
-
@yogis40
Sorry, i’ve Forgotten to ask my question.
How do we catch when the user is clicking on ‘Clear’ menu ? Is it possible to specify the ‘Clear’ in the QMenu::triggered(&Clear)
?
Thanks for your help and sorry to ask but I’m a newbie and struggle with Qt. -
It's not exactly a Qt problem. It's what you are trying to do. You're going against the UI guidelines of all desktop environments and against the normal usage of a menu.
The content of the menu bar is menus. Clicking on a menu should not trigger anythings else that showing its content.
Your clear action should be in for example an edit menu. You can put accelerator on it and even a keyboard shortcut.
-
Hi
Just had a test.
connect(ui->menuClear,&QMenu::triggered, ui->textEdit, &QTextEdit::clear);
does not work as a top menu (with no sub items) added in Designer does not call triggered.
(it has no QAction to be triggered)
That is why its not working - as its expected to have sub items.That said, its possible from code, using an QAction instead.
QAction *a = new QAction("Clear", this); ui->menuBar->addAction(a); connect(a, &QAction::triggered, ui->textEdit, &QTextEdit::clear);
That works however as SGist says, its not really a normal way for menus to work seen
from a users perspective. a clear command would normally be in Edit sub menu. -
Hello,
Thanks for your help and your answers.Regarding the UI guidelines, I’m interested to found it. As mentioned previuously, I’m newbie in Qt and the last time I’ve programmed a UI it was in Visual Basic in 2004. Then, 15-years ago...
Thanks.
-
@yogis40
Hi
Welcome back to GUI programming then :)
Such single click activation commands are often put in the QToolbar
(Lives just under the menu) -
@yogis40 said in Menu without action:
Regarding the UI guidelines, I’m interested to found it. As mentioned previuously, I’m newbie in Qt and the last time I’ve programmed a UI it was in Visual Basic in 2004. Then, 15-years ago...
There's per platform:
15/16