- UID
- 1029342
- 性别
- 男
|
1.
编写下拉菜单程序
mainwidget.h
#include <qpopupmenu.h>
#include <qmenubar.h>
#include <qlabel.h>
#include <qtoolbar.h>
#include <qtoolbutton.h>
#include <qstatusbar.h>
class MyMainWidget: public QMainWindow
{
Q_OBJECT
public:
MyMainWidget( QWidget*parent=0, const char *name=0 );
public slots:
void newFile();
void openFile();
void saveFile();
void exitMain();
void copyFile();
private:
QLabel *statuslabel;
};
#endif
//如下(加粗)可以看到在我们需要汉化的地方都用tr()方法进行标识,利用lupdate就可提取出其中需要汉化的源文字,从而生成.ts文件。
mainwidget.cpp
#include "mainwidget.h"
MyMainWidget::MyMainWidget( QWidget*parent, const char *name )
MainWindow( parent,name )
{
setCaption(MyMainWidget::tr("chineseqt Example"));
setBackgroundColor( white );
statuslabel = new QLabel("", this );
statuslabel->setGeometry(50, 50, 250, 50 );
statuslabel->setBackgroundColor( white );
QPopupMenu *filemenu1 = newQPopupMenu;
filemenu1->insertItem(QPopupMenu::tr("&New"),this, SLOT( newFile() ),CTRL+Key_N );
filemenu1->insertItem(QPopupMenu::tr("&Open"), this,SLOT( openFile() ),CTRL+Key_O );
filemenu1->insertItem(QPopupMenu::tr("&Save"),this, SLOT( saveFile() ), CTRL+Key_S );
filemenu1->insertSeparator();
filemenu1->insertItem(QPopupMenu::tr("E&xit"), this,SLOT( exitMain() ),CTRL+Key_X );
QPopupMenu *filemenu2 = newQPopupMenu;
filemenu2->insertItem(QPopupMenu::tr("&Copy"),this, SLOT( copyFile() ),CTRL+Key_C );
QMenuBar *menubar;
menubar = new QMenuBar( this );
menubar->insertItem(QMenuBar::tr("&File"),filemenu1);
menubar->insertItem(QMenuBar::tr("&Edit"), filemenu2);
statusBar()->message(MyMainWidget::tr("Ready"));
} |
|