Direct binding shortcuts, the following is a button bindings shortcuts.
ui -> btnNext -> setShortcut ( TR ( "Right" )); // button "next"
UI -> btnPrevious -> setShortcut ( TR ( "Left" )); "Previous" button //
UI -> actLoadSet -> setShortcut ( TR ( "the F4" )); // the button "load configuration"
UI -> btnGetFinalImg -> setShortcut ( QKeySequence ( QLatin1String ( "the Alt + D" ))); // the button "Import"
UI -> btnautobp -> setShortcut ( TR ( "F2 of" )); // the button "process"
UI -> btnZoomIn -> setShortcut ( QKeySequence ( QLatin1String ( "PgUp" ))); // the button "zoom +"
ui -> btnZoomOut -> setShortcut ( QKeySequence ( QLatin1String ( "PgDown" ))); // button to "zoom -"
Rewriting keyboard events keyPressEvent virtual function, do not forget to add <QKeyEvent> header, the following code is loaded alt + s settings file.
void MainWindow::keyPressEvent(QKeyEvent *event)
{
if (event->modifiers() & Qt::AltModifier)
{
IF ( Event -> Key () == Qt :: Key_S ) // touch trigger
{
settingsPath = QFileDialog :: getOpenFileName ( the this , QString ( QString :: fromUtf8 ( "load configuration" )), "" , QString ( "* .ini" ), 0 , 0 ); // when it is pressed alt + s open the file selection dialog
settingsName = settingsPath . sectionTop ( "/" , - . 1 , - . 1 , QString :: SectionSkipEmpty ); // get the data following the slash, document name
ui -> textinfo1 -> setText ( settingsName ); // display the file name on the screen
LoadSettings ( settingsPath ); // call to load the settings information
}
}
}
Reference code:
https://blog.csdn.net/qq_37233607/article/details/78417769