• 3832阅读
  • 4回复

如何做不弹出的菜单,即没有子菜单。。。。。。。 [复制链接]

上一主题 下一主题
离线sun83819
 
只看楼主 正序阅读 楼主  发表于: 2010-03-01
  1. OrderComm::COrderComm(QWidget  *parent)
  2.     : QMainWindow(parent)
  3.     {
  4.     
  5.     menubar = new QMenuBar(this);
  6.     menubar->setObjectName(QString::fromUtf8("menubar"));
  7.     this->setMenuBar(menubar);
  8.             
  9.     createMyMenu();
  10.     
  11.         }
  12. void COrderComm::createMyMenu()
  13.     {    //add menu item help to menu    
  14.     menu_helpAction = new QAction(tr("订购"), this);    
  15.     menuBar()->addAction(menu_helpAction);    
  16.     connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));    
  17.     }


这样出来的效果始终是  有个“option”点击之后才弹出“订购”
现在我想不弹出,直接就是一个"订购“,如何实现
离线sun83819
只看该作者 4楼 发表于: 2010-03-02
我用的qt开发塞班手机,是不是手机的问题,呵呵
离线wader
只看该作者 3楼 发表于: 2010-03-02
可能是你其它地方的代码问题,我做的测试只有三个文件,贴在下面

  1. // main.cpp
  2. #include <QtGui>
  3. #include "mainwindow.h"
  4. int main(int argc, char *argv[])
  5. {
  6.     QApplication a(argc, argv);
  7.     QTextCodec::setCodecForTr(QTextCodec::codecForLocale());
  8.     MainWindow w;
  9.     w.show();
  10.     return a.exec();
  11. }


  1. // mainwindow.h
  2. #ifndef MAINWINDOW_H
  3. #define MAINWINDOW_H
  4. #include <QMainWindow>
  5. class MainWindow : public QMainWindow {
  6.     Q_OBJECT
  7. public:
  8.     MainWindow(QWidget *parent = 0);
  9. private slots:
  10.     void order();
  11. };
  12. #endif // MAINWINDOW_H


  1. // mainwindow.cpp
  2. #include <QtGui>
  3. #include "mainwindow.h"
  4. MainWindow::MainWindow(QWidget *parent) :
  5.     QMainWindow(parent)
  6. {
  7.     QAction* buyAction = new QAction(tr("订购"), this);
  8.     menuBar()->addAction(buyAction);
  9.     connect(buyAction, SIGNAL(triggered()), this, SLOT(order()));
  10. }
  11. void MainWindow::order()
  12. {
  13.     QMessageBox::information(this, tr("Message"), tr("请下订单!"));
  14. }
离线sun83819
只看该作者 2楼 发表于: 2010-03-02
引用第1楼wader于2010-03-02 03:17发表的  :
这样写就可以了
[code]
MainWindow::MainWindow(QWidget *parent) :
.......

貌似跟我写的没啥区别啊,,还是弹出了
离线wader
只看该作者 1楼 发表于: 2010-03-02
这样写就可以了

  1. MainWindow::MainWindow(QWidget *parent) :
  2.     QMainWindow(parent)
  3. {
  4.     QAction* buyAction = new QAction(tr("订购"), this);
  5.     menuBar()->addAction(buyAction);
  6.     connect(buyAction, SIGNAL(triggered()), this, SLOT(order()));
  7. }
  8. void MainWindow::order()
  9. {
  10.     QMessageBox::information(this, tr("Message"), tr("请下订单!"));
  11. }
快速回复
限100 字节
 
上一个 下一个