Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can ALT be coded as shortcut key?



  • In many drawing applications, Alt is the shortcut for the eyedropper tool.
    In the application I work on, we want to keep this as the default behavior, but it should be editable, in stead as hardcoded as it usually is.
    I can't git it to work. I have tried this:```

    QAction* eyedropperAlt = nullptr;
    

    in mainWindow.h, and

    eyedropperAlt = new QAction(this);
    connect(eyedropperAlt, &QAction::triggered, mToolBox, &ToolBoxWidget::eyedropperAltOn);
    eyedropperAlt->setShortcut(Qt::Key_Alt);
    

    in mainWindow.cpp.
    I have also tried to set Qt::Altmodifier as shortcut. Nothing works.
    Any suggestions?



  • @davidlamhauge
    Based purely on my intuition, if it doesn't work as-is then Alt is doubtless a modifier only and you need to go into something like keyPressEvent (e.g. https://stackoverflow.com/a/25005828/489865) to capture it?



  • Thanks! It worked.


Log in to reply