ui.pushButton->setFocus(); //设置默认焦点

ui.pushButton->setShortcut( QKeySequence::InsertParagraphSeparator ); //设置快捷键为键盘的“回车”键

ui.pushButton->setShortcut(Qt::Key_Enter); //设置快捷键为enter键

ui.pushButton->setShortcut(Qt::Key_Return); //设置快捷键为小键盘上的enter键

或者

ui.pushButton->setFocus(); //设置默认焦点

ui.pushButton->setDefault(); //设置默认按钮,设置了这个属性,当用户按下回车的时候,就会按下该按钮

当焦点在ui.pushButton这个按钮上的时候,按下回车,该按钮就发射clicked()信号。

相关文章:

  • 2022-12-23
  • 2022-02-21
  • 2022-01-09
  • 2022-12-23
  • 2021-08-15
  • 2022-01-03
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-06
  • 2021-12-17
  • 2022-12-23
相关资源
相似解决方案