simple-application-example.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 422 行 · 第 1/2 页

HTML
422
字号
<!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/application/application.doc:5 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A Complete Application Window</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&nbsp;Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main&nbsp;Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped&nbsp;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</h1> <p> <p> This example program looks like a complete modern application.  Ithas a menu bar, it has a tool bar, it has a status bar and workslike a simple text editor.<p> There is a <a href="simple-application.html">walkthrough</a> ofthis example.<p> <hr><p> Header file:<p> <pre>/****************************************************************************** $Id:  qt/application.h   3.0.5   edited May 7 17:30 $**** 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 &lt;<a href="qmainwindow-h.html">qmainwindow.h</a>&gt;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> &amp;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$**** Copyright (C) 1992-2002 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 &lt;<a href="qimage-h.html">qimage.h</a>&gt;#include &lt;<a href="qpixmap-h.html">qpixmap.h</a>&gt;#include &lt;<a href="qtoolbar-h.html">qtoolbar.h</a>&gt;#include &lt;<a href="qtoolbutton-h.html">qtoolbutton.h</a>&gt;#include &lt;<a href="qpopupmenu-h.html">qpopupmenu.h</a>&gt;#include &lt;<a href="qmenubar-h.html">qmenubar.h</a>&gt;#include &lt;<a href="qtextedit-h.html">qtextedit.h</a>&gt;#include &lt;<a href="qfile-h.html">qfile.h</a>&gt;#include &lt;<a href="qfiledialog-h.html">qfiledialog.h</a>&gt;#include &lt;<a href="qstatusbar-h.html">qstatusbar.h</a>&gt;#include &lt;<a href="qmessagebox-h.html">qmessagebox.h</a>&gt;#include &lt;<a href="qprinter-h.html">qprinter.h</a>&gt;#include &lt;<a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a href="qaccel-h.html">qaccel.h</a>&gt;#include &lt;<a href="qtextstream-h.html">qtextstream.h</a>&gt;#include &lt;<a href="qpainter-h.html">qpainter.h</a>&gt;#include &lt;<a href="qpaintdevicemetrics-h.html">qpaintdevicemetrics.h</a>&gt;#include &lt;<a href="qwhatsthis-h.html">qwhatsthis.h</a>&gt;#include "filesave.xpm"#include "fileopen.xpm"#include "fileprint.xpm"<a name="f448"></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="qpixmap.html">QPixmap</a> openIcon, saveIcon, printIcon;    <a href="qtoolbar.html">QToolBar</a> * fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" );<a name="x1541"></a>    fileTools-&gt;<a href="qtoolbar.html#setLabel">setLabel</a>( "File Operations" );    openIcon = QPixmap( fileopen );    QToolButton * fileOpen        = new <a href="qtoolbutton.html">QToolButton</a>( openIcon, "Open File", <a href="qstring.html#QString-null">QString::null</a>,                           this, SLOT(choose()), fileTools, "open file" );    saveIcon = QPixmap( filesave );    QToolButton * fileSave        = new <a href="qtoolbutton.html">QToolButton</a>( saveIcon, "Save File", QString::null,                           this, SLOT(save()), fileTools, "save file" );    printIcon = QPixmap( fileprint );    QToolButton * filePrint        = new <a href="qtoolbutton.html">QToolButton</a>( printIcon, "Print File", QString::null,                           this, SLOT(print()), fileTools, "print file" );    (void)QWhatsThis::whatsThisButton( fileTools );    const char * fileOpenText = "&lt;p&gt;&lt;img source=\"fileopen\"&gt; "                 "Click this button to open a &lt;em&gt;new file&lt;/em&gt;. &lt;br&gt;"                 "You can also select the &lt;b&gt;Open&lt;/b&gt; command "                 "from the &lt;b&gt;File&lt;/b&gt; menu.&lt;/p&gt;";<a name="x1542"></a>    QWhatsThis::<a href="qwhatsthis.html#add">add</a>( fileOpen, fileOpenText );<a name="x1522"></a>    QMimeSourceFactory::<a href="qmimesourcefactory.html#defaultFactory">defaultFactory</a>()-&gt;setPixmap( "fileopen", openIcon );    const char * fileSaveText = "&lt;p&gt;Click this button to save the file you "                 "are editing. You will be prompted for a file name.\n"                 "You can also select the &lt;b&gt;Save&lt;/b&gt; command "                 "from the &lt;b&gt;File&lt;/b&gt; menu.&lt;/p&gt;";    QWhatsThis::<a href="qwhatsthis.html#add">add</a>( fileSave, fileSaveText );    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.";    QWhatsThis::<a href="qwhatsthis.html#add">add</a>( filePrint, filePrintText );    <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this );    <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertItem( "&amp;File", file );    file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;New", this, SLOT(newDoc()), CTRL+Key_N );    int id;    id = file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( openIcon, "&amp;Open...",                           this, SLOT(choose()), CTRL+Key_O );<a name="x1518"></a>    file-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileOpenText );    id = file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( saveIcon, "&amp;Save",                           this, SLOT(save()), CTRL+Key_S );    file-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );    id = file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Save &amp;As...", this, SLOT(saveAs()) );    file-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );    file-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();    id = file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( printIcon, "&amp;Print...",                           this, SLOT(print()), CTRL+Key_P );    file-&gt;<a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, filePrintText );    file-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();    file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Close", this, SLOT(<a href="qwidget.html#close">close</a>()), CTRL+Key_W );<a name="x1507"></a>    file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;Quit", qApp, SLOT( <a href="qapplication.html#closeAllWindows">closeAllWindows</a>() ), CTRL+Key_Q );    <a href="qmainwindow.html#menuBar">menuBar</a>()-&gt;insertSeparator();    <a href="qpopupmenu.html">QPopupMenu</a> * help = new <a href="qpopupmenu.html">QPopupMenu</a>( this );

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?