PDA

View Full Version : Hide shorcut text of QMenu Action



KillGabio
15th January 2012, 23:53
I ve looking for an answer all over the internet but i dont seem to get one...

i ve tried changing the stylesheet but i think there's no option to do what i want

in the documentation i ve read that the action has: (icon-text-shorcut text), so what i want is to disable/hide the shorcut text

thanks!

ChrisW67
16th January 2012, 00:44
Well, we could could guess what you are trying to achieve, what you are doing, and what the result is... or you could show us with a screen shot or a small, compilable example that displays the problem and what you have tried.

KillGabio
16th January 2012, 01:54
lol, ok.. i want Ctrl+F to disappear :/

7274

Spitfire
17th January 2012, 12:46
What is that?
Is it a QPushButton, QToolButton, QMenu or something else?
Some code how you construct that element would be nice.

Getting rid of that text will be different depending on what it is.
General idea would be not to add the action to that item but to something else, ie parent widget.
Action will still be triggered but the text will not be displayed.

KillGabio
17th January 2012, 23:45
hi, sorry for the delay.

it`s an QAction from the QMenu->QMenuBar->QMainWindow

i just did that with the QDesigner so the mainwindow implements everything

Spitfire
19th January 2012, 10:43
Ok, I have no idea how to hide the shortcut text from action without disabling it (the shortcut).
Other approach could be not to set the shortcut on the action but add it (the shortcut) to the main window, something like this:

MainWindow::MainWindow( QWidget* parent )
: QMainWindow( parent )
{
QMenu* m = this->menuBar()->addMenu( "test" );
m->addAction( "close", this, SLOT( close() ) ); // action will not have a shortcut but will still do the right thing when clicked

QShortcut* s = new QShortcut( Qt::CTRL + Qt::Key_Q, this );
connect( s, SIGNAL( activated()), a, SLOT( trigger() ) ); // shortcut is not visible but will trigger the action which in trun will do the right thing
}
You can't do that from the designer though.