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 ) );
    @connect(m_fileZoomInAction,SIGNAL(triggered()),this,SLOT(zoomIn()));
    @ 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

    Hi,

    You should rather use:

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

    or add

    @m_MenuButton->addAction(m_fileZoomInAction);@

    to your code

    Hope it helps


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.