Hello, the code below allows to apply not English mnemonics for standard widgets

Qt Code:
  1. // shortcuts.h
  2. class QWidget; //forward declaration - for faster compilation
  3. class QKeyEvent; //forward declaration- for faster compilation
  4. bool checkWidgetShortcuts(QWidget*widget,QKeyEvent*ev);
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. // shortcuts.cpp
  2. #include <QWidget>
  3. #include <QKeyEvent>
  4. #include <QAbstractButton>
  5. #include <QLabel>
  6. #include <QTabWidget>
  7. #include "qglobal.h"
  8. namespace {
  9. struct SItem
  10. {
  11. enum EType {
  12. BUTTON,
  13. LABEL,
  14. TAB
  15. } type;
  16. int data;
  17. SItem(QWidget*_w,EType _t,int _d=0) : w(_w),type(_t),data(_d) {}
  18. };
  19. QList<QWidget*> visible_widgets(QWidget*w)
  20. {
  21. QList<QWidget*> list;
  22. Q_ASSERT(w);
  23. if(w->isVisible() && w->isEnabled()) {
  24. list.append(w);
  25. foreach(QObject*child,w->children())
  26. if(child->isWidgetType())
  27. list << visible_widgets(qobject_cast<QWidget*>(child));
  28. }
  29. return list;
  30. }
  31. } //anonymus namespace
  32. bool checkWidgetShortcuts(QWidget*widget,QKeyEvent*ev)
  33. {
  34. Q_ASSERT(widget && ev);
  35. bool ret_val = false;
  36. int shift = (ev->modifiers() & Qt::ShiftModifier) ? (int)Qt::SHIFT : 0;
  37. int ctrl = (ev->modifiers() & Qt::ControlModifier) ? (int)Qt::CTRL : 0;
  38. int alt = (ev->modifiers() & Qt::AltModifier) ? (int)Qt::ALT : 0;
  39. QKeySequence ks(ev->key() + shift + ctrl + alt);
  40. QList<SItem>list;
  41. foreach(QWidget*cw,visible_widgets(widget)) {
  42. if(qobject_cast<QAbstractButton*>(cw)) {
  43. QAbstractButton*but = qobject_cast<QAbstractButton*>(cw);
  44. if(but->shortcut() == ks)
  45. list.append(SItem(but,SItem::BUTTON));
  46. } else if(qobject_cast<QLabel*>(cw)) {
  47. QLabel*label = qobject_cast<QLabel*>(cw);
  48. if(label->buddy() && label->buddy()->isVisible()
  49. && (ks == QKeySequence::mnemonic(label->text())))
  50. {
  51. list.append(SItem(label->buddy(),SItem::LABEL));
  52. }
  53. } else if(qobject_cast<QTabWidget*>(cw)) {
  54. QTabWidget*tab = qobject_cast<QTabWidget*>(cw);
  55. for(int i=0;i<tab->count();i++)
  56. if(ks == QKeySequence::mnemonic(tab->tabText(i))) {
  57. list.append(SItem(tab,SItem::TAB,i));
  58. break;
  59. }
  60. }
  61. }
  62. if(list.count()) {
  63. int index = 0;
  64. int last = list.count()-1;
  65. for(int i=last;i>=0;i--) {
  66. if(list.at(i).w->hasFocus()) {
  67. index = (i == last) ? 0 : (i+1);
  68. break;
  69. }
  70. }
  71. const SItem& item = list.at(index);
  72. item.w->setFocus();
  73. switch(item.type) {
  74. case SItem::BUTTON: qobject_cast<QAbstractButton*>(item.w)->click(); break;
  75. case SItem::LABEL: break; //do nothing - just check
  76. case SItem::TAB: qobject_cast<QTabWidget*>(item.w)->setCurrentIndex(item.data); break;
  77. default: Q_ASSERT(false); break;
  78. }
  79. ev->accept();
  80. ret_val = true;
  81. } else {
  82. ev->ignore();
  83. }
  84. return ret_val;
  85. }
To copy to clipboard, switch view to plain text mode 

Example:
Qt Code:
  1. void CMainWindow::keyPressEvent(QKeyEvent*event)
  2. {
  3. if(!checkWidgetShortcuts(this,event)) {
  4. // do something with keyevent if needed
  5. }
  6. }
To copy to clipboard, switch view to plain text mode 

Profit =)