I'm tryin to add shortcuts to the QMenu and QActions, but i'm having a little trouble.

I tryed the http://doc.qt.nokia.com/latest/mainwindows-menus.html, but somehow it doesnt work the same way and I'm confused.

I made the QAction KeyShortcut work, but it isnt underlining the letter that I tell the program too. I tryed several diferente ways to make that happen but it just doesnt.

Problems:
- Cant add shortcut to menubar (as an example for the File)
- Cant make the menuBar or QActions underline the letter of its shortchut
- I tryed the tr("&File") and ("&File"), it wont go eitherway...

Anyideas?

Heres the .cpp code for analisys

Qt Code:
  1. #include "teste3mainwindow.h"
  2. #include "ui_teste3mainwindow.h"
  3. #include <QGraphicsView>
  4. #include <QGraphicsScene>
  5. #include <QGraphicsTextItem>
  6. #include <QIcon>
  7. #include <QAction>
  8. #include <QWidget>
  9. #include <QMenu>
  10. #include <QMenuBar>
  11.  
  12.  
  13.  
  14. teste3MainWindow::teste3MainWindow(QWidget *parent) :
  15. QMainWindow(parent),
  16. ui(new Ui::teste3MainWindow)
  17. {
  18. ui->setupUi(this);
  19.  
  20. createActions();
  21. createMenus();
  22. createToolBar();
  23.  
  24.  
  25. //Cria um QGraphicsScene com um QGraphicView como parent
  26. QGraphicsScene *scene = new QGraphicsScene(ui->view);
  27. QGraphicsTextItem *item = new QGraphicsTextItem("MaDog");
  28.  
  29. //ativa a possibilidade de mover o objeto
  30. //Cada objeto tem um tamanho especÃ*fico, devemos descobrir como alterar
  31. //essa propriedade intrÃ*nseca para melhor manipulá-lo
  32. item->setFlag(QGraphicsItem::ItemIsMovable,true);
  33.  
  34. scene->addItem(item);
  35.  
  36. ui->view->setScene(scene);
  37. ui->view->show();
  38.  
  39. //Faz com que o view (QGraphicsView) assuma o tamanho da janela. Ela altera
  40. //seu tamanho de acordo com a QMainWindow
  41. teste3MainWindow::setCentralWidget(ui->view);
  42.  
  43.  
  44.  
  45.  
  46.  
  47. }
  48.  
  49. teste3MainWindow::~teste3MainWindow()
  50. {
  51. delete ui;
  52. }
  53.  
  54. //slots
  55. void teste3MainWindow::newFile()
  56. {
  57. scene = new QGraphicsScene(this);
  58. QGraphicsTextItem *item = new QGraphicsTextItem("NewFile");
  59.  
  60. scene->addItem((item));
  61. ui->view->setScene(scene);
  62. }
  63.  
  64.  
  65. //private functions
  66.  
  67. void teste3MainWindow::createActions()
  68. {
  69. newAction = new QAction(tr("&New"),this);
  70. newAction->setShortcut(QKeySequence::New);
  71. //newAction->setIcon(QIcon(":/images/circulo.png"));
  72. newAction->setStatusTip(tr("omg!!"));
  73. connect(newAction,SIGNAL(triggered()),this,SLOT(newFile()));
  74.  
  75. newAction2 = new QAction(tr("&New"),this);
  76. //newAction2->setShortcut(QKeySequence::New);
  77. newAction2->setStatusTip(tr("omg!!"));
  78. connect(newAction2,SIGNAL(triggered()),this,SLOT(newFile()));
  79. }
  80.  
  81. void teste3MainWindow::createMenus()
  82. {
  83. fileMenu = menuBar()->addMenu("&File");
  84. fileMenu->addAction(newAction);
  85. fileMenu->addSeparator();
  86. fileMenu->addAction(newAction2);
  87.  
  88. editMenu = menuBar()->addMenu(tr("&Edit"));
  89. }
  90.  
  91. void teste3MainWindow::createToolBar()
  92. {
  93. ui->toolBar->addAction(newAction);
  94. ui->toolBar->addSeparator();
  95. ui->toolBar->addAction(newAction2);
  96. }
To copy to clipboard, switch view to plain text mode 

Thanks