如何做不弹出的菜单,即没有子菜单。。。。。。。

god_sun 2010-03-02 09:06:43
如何做不弹出的菜单,即没有子菜单。。。。。。。

codeOrderComm::COrderComm(QWidget *parent)
: QMainWindow(parent)
{

menubar = new QMenuBar(this);
menubar->setObjectName(QString::fromUtf8("menubar"));
this->setMenuBar(menubar);

createMyMenu();

}

void COrderComm::createMyMenu()
{ //add menu item help to menu
menu_helpAction = new QAction(tr("订购"), this);
menuBar()->addAction(menu_helpAction);
connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));

}




这样出来的效果始终是 有个“option”点击之后才弹出“订购”
现在我想不弹出,直接就是一个"订购“,如何实现
...全文
241 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
不弹出菜单的菜单,那还叫菜单吗?那你直接加个Action好了,这样多省事

LZ是不是这个意思?
dyw 2010-03-05
  • 打赏
  • 举报
回复
(copied from mailing list)

>
>How to change the menu bar name in QT?
>

I guess you mean the "Options" text in softkeys/cba in S60, which is added automatically to launch QMainWindow menubar? If yes then your alternatives are as follows:

1. Iterate through main window actions, and change the text of "Options" action as follows:

foreach (QAction *action, actions()) {
if (action->text() == tr("Options"))
action->setText("Anything!");
}

2. Provide application specific translation to "Options" softkey. Translation source (.ts) file would be something like:

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.0" language="uk_UA">
<context>
<name>QSoftKeyManager</name>
<message>
<location filename="../src/gui/kernel/qsoftkeymanager.cpp" line="+72"/>
<source>Options</source>
<translation>MyOwnText</translation>
</message>
</context>
</TS>

In addition you of course need to install the translator for application.

3. Provide your own left softkey and associate QMenu to something like this (In this case QMainWindow menubar is not used):

menu = new QMenu(this);
menu->addAction(tr("Menu item 1"), this, SLOT(menuItemTriggered()));
ok = new QAction("MyMenu", this); // <-- "MyMenu goes to left softkey"
ok->setSoftKeyRole(QAction::PositiveSoftKey);
ok->setMenu(menu);
addAction(ok);
MicroSky2813 2010-03-03
  • 打赏
  • 举报
回复
我今天看了一下Symbian的,貌似这是Qt手机库已经固定好了的,我以前用j2me也有这种问题
god_sun 2010-03-03
  • 打赏
  • 举报
回复
引用 16 楼 microsky2813 的回复:
我今天看了一下Symbian的,貌似这是Qt手机库已经固定好了的,我以前用j2me也有这种问题


是啊,怎么样也去不掉,而且模拟器右边的总是exit菜单,也改不了
pywepe 2010-03-03
  • 打赏
  • 举报
回复
右键菜单好像是 什么 ContextMenu吧
dyw 2010-03-02
  • 打赏
  • 举报
回复
引用楼主 god_sun 的回复:
如何做不弹出的菜单,即没有子菜单。。。。。。。
...
menu_helpAction=new QAction(tr("订购"),this);
menuBar()->addAction(menu_helpAction);
...
现在我想不弹出,直接就是一个"订购“,如何实现

你的Qt什么版本,QMenuBar能添加QAction对象吗?

这样应该可以:
QAction* menu_helpAction = menuBar()->addAction(tr("<title>"));
connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));
MicroSky2813 2010-03-02
  • 打赏
  • 举报
回复
使用addMenu

楼主你说的我不明白什么意思
落随风 2010-03-02
  • 打赏
  • 举报
回复
帮顶~~~~~~~~~~~~~~~~~~~~
tuo_li 2010-03-02
  • 打赏
  • 举报
回复
帮你ding 亚 能成功把
zuoyechunfeng 2010-03-02
  • 打赏
  • 举报
回复
还是不太明白。。。。。。。。。
dyw 2010-03-02
  • 打赏
  • 举报
回复
哪来option字样?你在什么环境下运行?也看不到你发的图。我是在WindowsXP下运行的,做法没问题的,测试过的。
MicroSky2813 2010-03-02
  • 打赏
  • 举报
回复
引用 11 楼 god_sun 的回复:
引用 10 楼 microsky2813 的回复:引用 9 楼 god_sun 的回复:引用 8 楼 microsky2813 的回复:依然读不通什么意思的路过呵呵,哥们能看到图吗?我不是加了个hello的菜单吗?现在我想把hello放在options那里,就是说我不用点击option再弹出hello~我不要弹出的,想右边的exit一样如果是那样的话,用我二楼的方法就行了 C/C++ code MainWindow::MainWindow(QWidget*parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); QMenuBar*mb=new QMenuBar(this);this->setMenuBar(mb); QMenu*m1=new QMenu("1",mb); QMenu*m2=new QMenu("1",mb); mb->addMenu(m1); mb->addMenu(m2); }
还是老样子,呵呵。。options总是有


那貌似就是模拟器系统的设置了
god_sun 2010-03-02
  • 打赏
  • 举报
回复
引用 10 楼 microsky2813 的回复:
引用 9 楼 god_sun 的回复:引用 8 楼 microsky2813 的回复:依然读不通什么意思的路过呵呵,哥们能看到图吗?我不是加了个hello的菜单吗?现在我想把hello放在options那里,就是说我不用点击option再弹出hello~我不要弹出的,想右边的exit一样
如果是那样的话,用我二楼的方法就行了
C/C++ code
MainWindow::MainWindow(QWidget*parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMenuBar*mb=new QMenuBar(this);this->setMenuBar(mb);
QMenu*m1=new QMenu("1",mb);
QMenu*m2=new QMenu("1",mb);
mb->addMenu(m1);
mb->addMenu(m2);
}

还是老样子,呵呵。。options总是有
MicroSky2813 2010-03-02
  • 打赏
  • 举报
回复
引用 9 楼 god_sun 的回复:
引用 8 楼 microsky2813 的回复:依然读不通什么意思的路过
呵呵,哥们能看到图吗?
我不是加了个hello的菜单吗?
现在我想把hello放在options那里,就是说我不用点击option再弹出hello~
我不要弹出的,想右边的exit一样

如果是那样的话,用我二楼的方法就行了

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QMenuBar *mb=new QMenuBar(this);
this->setMenuBar(mb);
QMenu *m1=new QMenu("1",mb);
QMenu *m2=new QMenu("1",mb);
mb->addMenu(m1);
mb->addMenu(m2);
}

god_sun 2010-03-02
  • 打赏
  • 举报
回复
引用 8 楼 microsky2813 的回复:
依然读不通什么意思的路过

呵呵,哥们能看到图吗?
我不是加了个hello的菜单吗?
现在我想把hello放在options那里,就是说我不用点击option再弹出hello~
我不要弹出的,想右边的exit一样
MicroSky2813 2010-03-02
  • 打赏
  • 举报
回复
依然读不通什么意思的路过
god_sun 2010-03-02
  • 打赏
  • 举报
回复
引用 6 楼 dyw 的回复:
我是试过是可以的。用向导生成一个Qt Gui Application:

MainWindow.cpp代码:
C/C++ code#include"mainwindow.h"
#include"ui_mainwindow.h"
#include<QMessageBox>

MainWindow::MainWindow(QWidget*parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QAction* hello= menuBar()->addAction(tr("Hello"));// QAction* hello = ui->menuBar->addAction(tr("Hello")); connect(hello, SIGNAL(triggered()),this, SLOT(sayHello()));
}

MainWindow::~MainWindow()
{
delete ui;
}void MainWindow::changeEvent(QEvent*e)
{
QMainWindow::changeEvent(e);switch (e->type()) {case QEvent::LanguageChange:
ui->retranslateUi(this);break;default:break;
}
}void MainWindow::sayHello()
{
QMessageBox mbox;
mbox.setText("Hello");
mbox.exec();
}

MainWindow.ui代码:
XML code<?xml version="1.0" encoding="UTF-8"?><uiversion="4.0"><class>MainWindow</class><widgetclass="QMainWindow" name="MainWindow"><propertyname="geometry"><rect><x>0</x><y>0</y><width>600</width><height>400</height></rect></property><propertyname="windowTitle"><string>MainWindow</string></property><widgetclass="QWidget" name="centralWidget"/><widgetclass="QMenuBar" name="menuBar"><propertyname="geometry"><rect><x>0</x><y>0</y><width>600</width><height>19</height></rect></property></widget><widgetclass="QToolBar" name="mainToolBar"><attributename="toolBarArea"><enum>TopToolBarArea</enum></attribute><attributename="toolBarBreak"><bool>false</bool></attribute></widget><widgetclass="QStatusBar" name="statusBar"/></widget><layoutdefaultspacing="6" margin="11"/><resources/><connections/></ui>


这就奇怪了,我也刚新建了一个qt gui main window的工程
ui的xml拷贝你的。。
然后程序就写了这一行:

mainwindow::mainwindow(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
QAction* hello = menuBar()->addAction(tr("Hello"));

}


模拟器一运行:

还是有option字样,点开
dyw 2010-03-02
  • 打赏
  • 举报
回复
我是试过是可以的。用向导生成一个Qt Gui Application:

MainWindow.cpp代码:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMessageBox>

MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QAction* hello = menuBar()->addAction(tr("Hello"));
// QAction* hello = ui->menuBar->addAction(tr("Hello"));
connect(hello, SIGNAL(triggered()), this, SLOT(sayHello()));
}

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

void MainWindow::changeEvent(QEvent *e)
{
QMainWindow::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
ui->retranslateUi(this);
break;
default:
break;
}
}

void MainWindow::sayHello()
{
QMessageBox mbox;
mbox.setText("Hello");
mbox.exec();
}



MainWindow.ui代码:
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QMainWindow" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>400</height>
</rect>
</property>
<property name="windowTitle">
<string>MainWindow</string>
</property>
<widget class="QWidget" name="centralWidget"/>
<widget class="QMenuBar" name="menuBar">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>600</width>
<height>19</height>
</rect>
</property>
</widget>
<widget class="QToolBar" name="mainToolBar">
<attribute name="toolBarArea">
<enum>TopToolBarArea</enum>
</attribute>
<attribute name="toolBarBreak">
<bool>false</bool>
</attribute>
</widget>
<widget class="QStatusBar" name="statusBar"/>
</widget>
<layoutdefault spacing="6" margin="11"/>
<resources/>
<connections/>
</ui>
god_sun 2010-03-02
  • 打赏
  • 举报
回复

COrderComm::COrderComm(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle(tr("金叶移动商务业务代理平台"));

setWindowIcon(QIcon(":/images/icon.png"));

QAction* menu_helpAction = menuBar()->addAction(tr("aaa"));
connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));

}
god_sun 2010-03-02
  • 打赏
  • 举报
回复
引用 3 楼 dyw 的回复:
引用楼主 god_sun 的回复:如何做不弹出的菜单,即没有子菜单。。。。。。。 ... menu_helpAction=new QAction(tr("订购"),this); menuBar()->addAction(menu_helpAction); ... 现在我想不弹出,直接就是一个"订购“,如何实现
你的Qt什么版本,QMenuBar能添加QAction对象吗?

这样应该可以:
QAction* menu_helpAction = menuBar()->addAction(tr(" <title>"));
connect(menu_helpAction, SIGNAL(triggered()), this, SLOT(helpAction()));   

貌似还不行,,

16,240

社区成员

发帖
与我相关
我的任务
社区描述
Qt 是一个跨平台应用程序框架。通过使用 Qt,您可以一次性开发应用程序和用户界面,然后将其部署到多个桌面和嵌入式操作系统,而无需重复编写源代码。
社区管理员
  • Qt
  • 亭台六七座
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧