我正在尝试用Qt制作IHM,我开始制作一个基本菜单(文件,编辑......).到目前为止,我的菜单包含"文件",然后显示"新建项目,打开项目,退出".看起来很棒,但我的问题是我似乎无法触发这些动作(点击它们或按键快捷键).
这是我的插槽:
void KoriganEngine::launchNewProjectWidget(){
//External QWidget
m_nwProj = new NewProjectWidget(NULL,Qt::MSWindowsFixedSizeDialogHint);
m_nwProj->show();
}
Run Code Online (Sandbox Code Playgroud)
如果我在连接按钮时使用此插槽,我的新QWidget会正确显示.但是,动作不可能做同样的事情......
这是我的行为和菜单的代码:
void KoriganEngine::KG_createMenus(){
//init actions
KG_createMenuActions();
//add menu to the bar
m_fileMenu = menuBar()->addMenu("File");
m_fileMenu->addAction(m_newProjAction);
m_fileMenu->addAction(m_openProjAction);
m_fileMenu->addSeparator();
m_fileMenu->addAction(m_quitAction);
m_editMenu = menuBar()->addMenu("Edit");
Run Code Online (Sandbox Code Playgroud)
}
void KoriganEngine::KG_createMenuActions(){
m_newProjAction = new QAction("New Project...", this);
m_newProjAction->setShortcuts(QKeySequence::New);
m_newProjAction->setStatusTip(QString("Create a new Project"));
connect(m_newProjAction, SIGNAL(trigerred()), this, SLOT(slottest()));
m_openProjAction = new QAction("Open Project...", this);
m_openProjAction->setShortcuts(QKeySequence::Open);
m_openProjAction->activate( QAction::Hover);
connect(m_openProjAction, SIGNAL(trigerred()), this, SLOT(launchNewProjectWidget())); //TODO replace the slots
m_quitAction = new QAction("Exit", this);
connect(m_quitAction, SIGNAL(trigerred()), this, SLOT(quit()));
Run Code Online (Sandbox Code Playgroud)
}
以及使用按钮的代码: …