QT HTML5与菜单栏像真正的程序 [英] QT HTML5 with Menu Bar like real program
问题描述
我正在处理一个QT HTML5应用程序,我想知道如何添加一个顶级菜单,像正常程序(使用默认的文件,工具,帮助...
options)。
I'm working on an QT HTML5 application and I was wondering how i could add an top menu just like normal program ( with the default file, tools, help...
options ).
我认为我必须改变 html5applicationviewer.cpp
(我正在学习这个...)
I think that I've to change something in the html5applicationviewer.cpp
, but I've got 0 knowledge of that ( I'm learning this... )
即使你能给我一个正确的方向,我感谢。我已经搜索过,但发现绝对没有关于这个话题(但也许我没有搜索正确...)
Even if you could point me a little bit in the right direction, I'm grateful. I've searched around, but found absolutely nothing about this topic ( but maybe i didn't search right... )
如果你需要更多的信息,请问。
If you need more info, please ask.
推荐答案
将正常的桌面菜单添加到Qt应用程序的最简单的方法是使用 QMainWindow
,它拥有对菜单的良好支持。
Simplest way to add normal "desktop"-style menus to a Qt app is to use QMainWindow
which has good support for menus.
这里有一些东西让你开始。首先,我使用Qt Creator(SDK版本5.2.1)创建了默认的HTML5 Qt应用程序。然后我编辑了 main.cpp 并添加了一些行。结果如下,原始行没有注释,所有添加的行都有注释。
Here's something to get you started. First I created the default HTML5 Qt application with Qt Creator (SDK version 5.2.1). Then I edited the main.cpp and added some lines. Result is below, original lines without comment and all added lines with comment.
#include <QApplication>
#include <QMainWindow> // added
#include <QMenuBar> // added
#include <QMenu> // added
#include <QAction> // added
#include "html5applicationviewer.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QMainWindow w; // important, viewer is in stack so w must be before it!
Html5ApplicationViewer viewer;
w.setCentralWidget(&viewer); // set viewer as the central widget
QMenu *fileMenu = w.menuBar()->addMenu("&File"); // create file menu
QAction *exitAction = fileMenu->addAction("&Exit"); // create exit action
QObject::connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); // make the action do something
viewer.setOrientation(Html5ApplicationViewer::ScreenOrientationAuto);
//viewer.showExpanded(); // will be shown by main window
viewer.loadFile(QLatin1String("html/index.html"));
w.show(); // show main window
return app.exec();
}
这篇关于QT HTML5与菜单栏像真正的程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!