qaction-application-example.html
来自「QT 下载资料仅供参考」· HTML 代码 · 共 436 行 · 第 1/2 页
HTML
436 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/examples/action/application.doc:5 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A Complete Application Window with Actions</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>A Complete Application Window with Actions</h1> <p> <p> This example program is just like the application example,but uses <a href="qaction.html">QAction</a> to build the menu and the toolbar.<p> The QAction related part of the program is covered indetail by the <a href="simple-application-action.html">QAction application walkthrough</a> whilst the <a href="simple-application.html">Simple application walkthrough</a>deals with the rest.<p> <hr><p> Header file:<p> <pre>/****************************************************************************** $Id: qt/application.h 3.0.5 edited Oct 12 2001 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#ifndef APPLICATION_H#define APPLICATION_H#include <<a href="qmainwindow-h.html">qmainwindow.h</a>>class QTextEdit;class ApplicationWindow: public <a href="qmainwindow.html">QMainWindow</a>{ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>public: ApplicationWindow(); ~ApplicationWindow();protected: void closeEvent( <a href="qcloseevent.html">QCloseEvent</a>* );private slots: void newDoc(); void choose(); void load( const <a href="qstring.html">QString</a> &fileName ); void save(); void saveAs(); void print(); void about(); void aboutQt();private: <a href="qprinter.html">QPrinter</a> *printer; <a href="qtextedit.html">QTextEdit</a> *e; <a href="qstring.html">QString</a> filename;};#endif</pre><p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id: qt/application.cpp 3.0.5 edited Oct 12 2001 $**** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.**** This file is part of an example program for Qt. This example** program may be used, distributed and modified without limitation.*******************************************************************************/#include "application.h"#include <<a href="qimage-h.html">qimage.h</a>>#include <<a href="qpixmap-h.html">qpixmap.h</a>>#include <<a href="qtoolbar-h.html">qtoolbar.h</a>>#include <<a href="qtoolbutton-h.html">qtoolbutton.h</a>>#include <<a href="qpopupmenu-h.html">qpopupmenu.h</a>>#include <<a href="qmenubar-h.html">qmenubar.h</a>>#include <<a href="qtextedit-h.html">qtextedit.h</a>>#include <<a href="qfile-h.html">qfile.h</a>>#include <<a href="qfiledialog-h.html">qfiledialog.h</a>>#include <<a href="qstatusbar-h.html">qstatusbar.h</a>>#include <<a href="qmessagebox-h.html">qmessagebox.h</a>>#include <<a href="qprinter-h.html">qprinter.h</a>>#include <<a href="qapplication-h.html">qapplication.h</a>>#include <<a href="qaccel-h.html">qaccel.h</a>>#include <<a href="qtextstream-h.html">qtextstream.h</a>>#include <<a href="qpainter-h.html">qpainter.h</a>>#include <<a href="qpaintdevicemetrics-h.html">qpaintdevicemetrics.h</a>>#include <<a href="qwhatsthis-h.html">qwhatsthis.h</a>>#include <<a href="qaction-h.html">qaction.h</a>>#include "filesave.xpm"#include "fileopen.xpm"#include "fileprint.xpm"<a name="f360"></a>ApplicationWindow::ApplicationWindow() : <a href="qmainwindow.html">QMainWindow</a>( 0, "example application main window", WDestructiveClose ){ printer = new <a href="qprinter.html">QPrinter</a>; <a href="qaction.html">QAction</a> * fileNewAction; <a href="qaction.html">QAction</a> * fileOpenAction; <a href="qaction.html">QAction</a> * fileSaveAction, * fileSaveAsAction, * filePrintAction; <a href="qaction.html">QAction</a> * fileCloseAction, * fileQuitAction; fileNewAction = new <a href="qaction.html">QAction</a>( "New", "&New", CTRL+Key_N, this, "new" );<a name="x1059"></a> <a href="qobject.html#connect">connect</a>( fileNewAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( newDoc() ) ); fileOpenAction = new <a href="qaction.html">QAction</a>( "Open File", QPixmap( fileopen ), "&Open", CTRL+Key_O, this, "open" ); <a href="qobject.html#connect">connect</a>( fileOpenAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( choose() ) ); const char * fileOpenText = "<p><img source=\"fileopen\"> " "Click this button to open a <em>new file</em>. <br>" "You can also select the <b>Open</b> command " "from the <b>File</b> menu.</p>";<a name="x1077"></a> QMimeSourceFactory::<a href="qmimesourcefactory.html#defaultFactory">defaultFactory</a>()->setPixmap( "fileopen",<a name="x1061"></a> fileOpenAction-><a href="qaction.html#iconSet">iconSet</a>().pixmap() );<a name="x1062"></a> fileOpenAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( fileOpenText ); fileSaveAction = new <a href="qaction.html">QAction</a>( "Save File", QPixmap( filesave ), "&Save", CTRL+Key_S, this, "save" ); <a href="qobject.html#connect">connect</a>( fileSaveAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( save() ) ); const char * fileSaveText = "<p>Click this button to save the file you " "are editing. You will be prompted for a file name.\n" "You can also select the <b>Save</b> command " "from the <b>File</b> menu.</p>"; fileSaveAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( fileSaveText ); fileSaveAsAction = new <a href="qaction.html">QAction</a>( "Save File As", "Save &as", 0, this, "save as" ); <a href="qobject.html#connect">connect</a>( fileSaveAsAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( saveAs() ) ); fileSaveAsAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( fileSaveText ); filePrintAction = new <a href="qaction.html">QAction</a>( "Print File", QPixmap( fileprint ), "&Print", CTRL+Key_P, this, "print" ); <a href="qobject.html#connect">connect</a>( filePrintAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( print() ) ); const char * filePrintText = "Click this button to print the file you " "are editing.\n You can also select the Print " "command from the File menu."; filePrintAction-><a href="qaction.html#setWhatsThis">setWhatsThis</a>( filePrintText ); fileCloseAction = new <a href="qaction.html">QAction</a>( "Close", "&Close", CTRL+Key_W, this, "close" ); <a href="qobject.html#connect">connect</a>( fileCloseAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , this, SLOT( <a href="qwidget.html#close">close</a>() ) ); fileQuitAction = new <a href="qaction.html">QAction</a>( "Quit", "&Quit", CTRL+Key_Q, this, "quit" );<a name="x1063"></a> <a href="qobject.html#connect">connect</a>( fileQuitAction, SIGNAL( <a href="qaction.html#activated">activated</a>() ) , qApp, SLOT( <a href="qapplication.html#closeAllWindows">closeAllWindows</a>() ) ); // populate a tool bar with some actions <a href="qtoolbar.html">QToolBar</a> * fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" );<a name="x1096"></a> fileTools-><a href="qtoolbar.html#setLabel">setLabel</a>( "File Operations" );<a name="x1060"></a> fileOpenAction-><a href="qaction.html#addTo">addTo</a>( fileTools ); fileSaveAction-><a href="qaction.html#addTo">addTo</a>( fileTools ); filePrintAction-><a href="qaction.html#addTo">addTo</a>( fileTools ); (void)QWhatsThis::whatsThisButton( fileTools ); // populate a menu with all actions <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this ); <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&File", file ); fileNewAction-><a href="qaction.html#addTo">addTo</a>( file ); fileOpenAction-><a href="qaction.html#addTo">addTo</a>( file ); fileSaveAction-><a href="qaction.html#addTo">addTo</a>( file ); fileSaveAsAction-><a href="qaction.html#addTo">addTo</a>( file ); file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>(); filePrintAction-><a href="qaction.html#addTo">addTo</a>( file ); file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>(); fileCloseAction-><a href="qaction.html#addTo">addTo</a>( file ); fileQuitAction-><a href="qaction.html#addTo">addTo</a>( file );
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?