PDA

View Full Version : menuBar not working right



21altf
27th October 2011, 14:16
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


#include "teste3mainwindow.h"
#include "ui_teste3mainwindow.h"
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QGraphicsTextItem>
#include <QIcon>
#include <QAction>
#include <QWidget>
#include <QMenu>
#include <QMenuBar>



teste3MainWindow::teste3MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::teste3MainWindow)
{
ui->setupUi(this);

createActions();
createMenus();
createToolBar();


//Cria um QGraphicsScene com um QGraphicView como parent
QGraphicsScene *scene = new QGraphicsScene(ui->view);
QGraphicsTextItem *item = new QGraphicsTextItem("MaDog");

//ativa a possibilidade de mover o objeto
//Cada objeto tem um tamanho especÃ*fico, devemos descobrir como alterar
//essa propriedade intrÃ*nseca para melhor manipulá-lo
item->setFlag(QGraphicsItem::ItemIsMovable,true);

scene->addItem(item);

ui->view->setScene(scene);
ui->view->show();

//Faz com que o view (QGraphicsView) assuma o tamanho da janela. Ela altera
//seu tamanho de acordo com a QMainWindow
teste3MainWindow::setCentralWidget(ui->view);





}

teste3MainWindow::~teste3MainWindow()
{
delete ui;
}

//slots
void teste3MainWindow::newFile()
{
scene = new QGraphicsScene(this);
QGraphicsTextItem *item = new QGraphicsTextItem("NewFile");

scene->addItem((item));
ui->view->setScene(scene);
}


//private functions

void teste3MainWindow::createActions()
{
newAction = new QAction(tr("&New"),this);
newAction->setShortcut(QKeySequence::New);
//newAction->setIcon(QIcon(":/images/circulo.png"));
newAction->setStatusTip(tr("omg!!"));
connect(newAction,SIGNAL(triggered()),this,SLOT(ne wFile()));

newAction2 = new QAction(tr("&New"),this);
//newAction2->setShortcut(QKeySequence::New);
newAction2->setStatusTip(tr("omg!!"));
connect(newAction2,SIGNAL(triggered()),this,SLOT(n ewFile()));
}

void teste3MainWindow::createMenus()
{
fileMenu = menuBar()->addMenu("&File");
fileMenu->addAction(newAction);
fileMenu->addSeparator();
fileMenu->addAction(newAction2);

editMenu = menuBar()->addMenu(tr("&Edit"));
}

void teste3MainWindow::createToolBar()
{
ui->toolBar->addAction(newAction);
ui->toolBar->addSeparator();
ui->toolBar->addAction(newAction2);
}


Thanks

FelixB
27th October 2011, 14:45
What OS do you use? AFAIK the underlining does not work on all systems...

21altf
27th October 2011, 16:10
Its Windows

Spitfire
27th October 2011, 16:57
The letter is only underlined when you press 'Alt' on the keyboard.