Results 1 to 4 of 4

Thread: menuBar not working right

  1. #1
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1

    Default menuBar not working right

    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

  2. #2
    Join Date
    Oct 2010
    Location
    Berlin, Germany
    Posts
    358
    Thanks
    18
    Thanked 68 Times in 66 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: menuBar not working right

    What OS do you use? AFAIK the underlining does not work on all systems...

  3. #3
    Join Date
    Oct 2011
    Posts
    9
    Thanks
    1

    Default Re: menuBar not working right

    Its Windows

  4. #4
    Join Date
    Sep 2011
    Location
    Manchester
    Posts
    538
    Thanks
    3
    Thanked 106 Times in 103 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: menuBar not working right

    The letter is only underlined when you press 'Alt' on the keyboard.

Similar Threads

  1. [QT] MenuBar
    By iVo1d in forum Qt Programming
    Replies: 2
    Last Post: 18th August 2010, 13:14
  2. Dialogs and MenuBar
    By vieraci in forum Qt Programming
    Replies: 5
    Last Post: 30th April 2009, 08:30
  3. Bar on menubar?
    By zgulser in forum Qt Tools
    Replies: 6
    Last Post: 14th January 2009, 08:07
  4. menuBar() Problem
    By Cutey in forum Qt Programming
    Replies: 9
    Last Post: 25th January 2007, 11:50
  5. Using the menubar
    By Steve in forum Newbie
    Replies: 10
    Last Post: 27th February 2006, 15:59

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.