Important: Please read the Qt Code of Conduct -

Show keyboard shortcut in tooltips automatically

  • Howdy,

    Suppose I have a QAction set like that:
    @QAction *undo = new QAction( QString::fromAscii( "Undo" ), parent );
    undo->setToolTip( QString::fromAscii( "Undo" ) );
    undo->setShortcut( QKeySequence( "Ctrl+Z" ) );

    Is there any automatic way to make the tool tip for that action appears as Undo (Ctrl+Z)?

    Thanks in advance,

  • I don't know if there is a built-in Qt way. I do it this way:
    static const QString UndoShortcut(QStringLiteral("Ctrl+Z"));
    static const QString UndoTooltip(QString("Undo - %1").arg(ModeShortcut));


Log in to reply