📄 application-main-cpp.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - application/main.cpp example file</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: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b> <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>A Complete Application Window</h1><br clear="all"> This example program looks like a complete modern application. It has a menu bar, it has a tool bar, it has a status bar and works like a simple text editor. There is a <a href="simple-application.html">walkthrough</a> of this example. <hr> Header file: <pre>/****************************************************************************** $Id: qt/examples/application/application.h 2.3.8 edited 2004-05-12 $**** 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 QMultiLineEdit;class QToolBar;class QPopupMenu;class ApplicationWindow: public QMainWindow{ Q_OBJECTpublic: ApplicationWindow(); ~ApplicationWindow();protected: void closeEvent( <a href="qcloseevent.html">QCloseEvent</a>* );private slots: void newDoc(); void load(); void load( const char *fileName ); void save(); void saveAs(); void print(); void about(); void aboutQt();private: <a href="qprinter.html">QPrinter</a> *printer; <a href="qmultilineedit.html">QMultiLineEdit</a> *e; <a href="qtoolbar.html">QToolBar</a> *fileTools; <a href="qstring.html">QString</a> filename;};#endif</pre> <hr> Implementation: <pre>/****************************************************************************** $Id: qt/examples/application/application.cpp 2.3.8 edited 2004-05-12 $**** 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 <qkeycode.h>#include <<a href="qmultilineedit-h.html">qmultilineedit.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 "filesave.xpm"#include "fileopen.xpm"#include "fileprint.xpm"const char * fileOpenText = "<img source=\"fileopen\"> ""Click this button to open a <em>new file</em>. <br><br>""You can also select the <b>Open command</b> from the File menu.";const char * fileSaveText = "Click this button to save the file you are ""editing. You will be prompted for a file name.\n\n""You can also select the Save command from the File menu.\n\n""Note that implementing this function is left as an exercise for the reader.";const char * filePrintText = "Click this button to print the file you ""are editing.\n\n""You can also select the Print command from the File menu.";ApplicationWindow::ApplicationWindow() : <a href="qmainwindow.html">QMainWindow</a>( 0, "example application main window", WDestructiveClose ){ int id; printer = new <a href="qprinter.html">QPrinter</a>; <a href="qpixmap.html">QPixmap</a> openIcon, saveIcon, printIcon; fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" ); fileTools->setLabel( <a href="qobject.html#2418a9">tr</a>( "File Operations" ) ); openIcon = QPixmap( fileopen ); <a href="qtoolbutton.html">QToolButton</a> * fileOpen = new <a href="qtoolbutton.html">QToolButton</a>( openIcon, "Open File", QString::null, this, SLOT(<a href=#433>load</a>()), fileTools, "open file" ); saveIcon = QPixmap( filesave ); <a href="qtoolbutton.html">QToolButton</a> * fileSave = new <a href="qtoolbutton.html">QToolButton</a>( saveIcon, "Save File", QString::null, this, SLOT(<a href=#434>save</a>()), fileTools, "save file" ); printIcon = QPixmap( fileprint ); <a href="qtoolbutton.html">QToolButton</a> * filePrint = new <a href="qtoolbutton.html">QToolButton</a>( printIcon, "Print File", QString::null, this, SLOT(<a href=#436>print</a>()), fileTools, "print file" ); (void)QWhatsThis::whatsThisButton( fileTools ); <a href="qwhatsthis.html#dfcd18">QWhatsThis::add</a>( fileOpen, fileOpenText ); <a href="qmimesourcefactory.html#5c7072">QMimeSourceFactory::defaultFactory</a>()->setPixmap( "fileopen", openIcon ); <a href="qwhatsthis.html#dfcd18">QWhatsThis::add</a>( fileSave, fileSaveText ); <a href="qwhatsthis.html#dfcd18">QWhatsThis::add</a>( filePrint, filePrintText ); <a href="qpopupmenu.html">QPopupMenu</a> * file = new <a href="qpopupmenu.html">QPopupMenu</a>( this ); <a href="qmainwindow.html#0eb7bc">menuBar</a>()->insertItem( "&File", file ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&New", this, SLOT(<a href=#431>newDoc</a>()), CTRL+Key_N ); id = file-><a href="qmenudata.html#deddb9">insertItem</a>( openIcon, "&Open", this, SLOT(<a href=#433>load</a>()), CTRL+Key_O ); file-><a href="qmenudata.html#88eb55">setWhatsThis</a>( id, fileOpenText ); id = file-><a href="qmenudata.html#deddb9">insertItem</a>( saveIcon, "&Save", this, SLOT(<a href=#434>save</a>()), CTRL+Key_S ); file-><a href="qmenudata.html#88eb55">setWhatsThis</a>( id, fileSaveText ); id = file-><a href="qmenudata.html#deddb9">insertItem</a>( "Save &as...", this, SLOT(<a href=#435>saveAs</a>()) ); file-><a href="qmenudata.html#88eb55">setWhatsThis</a>( id, fileSaveText ); file-><a href="qmenudata.html#e34b79">insertSeparator</a>(); id = file-><a href="qmenudata.html#deddb9">insertItem</a>( printIcon, "&Print", this, SLOT(<a href=#436>print</a>()), CTRL+Key_P ); file-><a href="qmenudata.html#88eb55">setWhatsThis</a>( id, filePrintText ); file-><a href="qmenudata.html#e34b79">insertSeparator</a>(); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Close", this, SLOT(<a href="qwidget.html#3d9c87">close</a>()), CTRL+Key_W ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); <a href="qpopupmenu.html">QPopupMenu</a> * help = new <a href="qpopupmenu.html">QPopupMenu</a>( this ); <a href="qmainwindow.html#0eb7bc">menuBar</a>()->insertSeparator(); <a href="qmainwindow.html#0eb7bc">menuBar</a>()->insertItem( "&Help", help ); help-><a href="qmenudata.html#deddb9">insertItem</a>( "&About", this, SLOT(<a href=#438>about</a>()), Key_F1 ); help-><a href="qmenudata.html#deddb9">insertItem</a>( "About &<a href="qt.html">Qt</a>", this, SLOT(<a href=#439>aboutQt</a>()) ); help-><a href="qmenudata.html#e34b79">insertSeparator</a>();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -