Important: Please read the Qt Code of Conduct -

How to add shortcut key in Qt

  • @QMenu *m_MenuButton;
    @ m_MenuButton = new QMenu(this);
    @ m_MenuButton->setGeometry(QRect(screen_w/1.1765,screen_h/12.3,500,00));
    @ m_MenuButton->setStyleSheet(QLatin1String("( QMenu::menu-indicator {subcontrol-position: left; }"));
    @ QAction *m_fileZoomInAction;
    @ m_fileZoomInAction = new QAction(m_MenuButton);
    @m_fileZoomInAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_Plus ) );
    @ m_MenuButton->addAction(m_fileZoomInAction);

    This is my code for zoom in ...its working fine but when i am trying to use shortcut key its not working fine.
    plss tell me what to do...

  • Lifetime Qt Champion


    You should rather use:

    @ m_fileZoomInAction = m_MenuButton.addAction(tr("Zoom In"))@

    or add


    to your code

    Hope it helps

Log in to reply