📄 mdi-example.html
字号:
<!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/mdi/mdi.doc:4 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>A MDI Application</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 MDI Application</h1> <p> This example program is just like the application example, but designed asMultiple Document Interface (MDI).<p> <hr><p> Header file:<p> <pre>/****************************************************************************** $Id: qt/application.h 3.0.5 edited Jun 5 14:11 $**** 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>>#include <<a href="qptrlist-h.html">qptrlist.h</a>>class QMultiLineEdit;class QToolBar;class QPopupMenu;class QWorkspace;class QPopupMenu;class QMovie;class MDIWindow: public <a href="qmainwindow.html">QMainWindow</a>{ <a href="metaobjects.html#Q_OBJECT">Q_OBJECT</a>public: MDIWindow( <a href="qwidget.html">QWidget</a>* parent, const char* name, int wflags ); ~MDIWindow(); void load( const <a href="qstring.html">QString</a>& fn ); void save(); void saveAs(); void print( <a href="qprinter.html">QPrinter</a>* );signals: void message(const <a href="qstring.html">QString</a>&, int );private: <a href="qmultilineedit.html">QMultiLineEdit</a>* medit; <a href="qmovie.html">QMovie</a> * mmovie; <a href="qstring.html">QString</a> filename;};class ApplicationWindow: public <a href="qmainwindow.html">QMainWindow</a>{ Q_OBJECTpublic: ApplicationWindow(); ~ApplicationWindow();private slots: MDIWindow* newDoc(); void load(); void save(); void saveAs(); void print(); void closeWindow(); void tileHorizontal(); void about(); void aboutQt(); void windowsMenuAboutToShow(); void windowsMenuActivated( int id );private: <a href="qprinter.html">QPrinter</a> *printer; <a href="qworkspace.html">QWorkspace</a>* ws; <a href="qtoolbar.html">QToolBar</a> *fileTools; <a href="qpopupmenu.html">QPopupMenu</a>* windowsMenu;};#endif</pre><p> <hr><p> Implementation:<p> <pre>/****************************************************************************** $Id: qt/application.cpp 3.0.5 edited Jun 5 14:13 $**** 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="qworkspace-h.html">qworkspace.h</a>>#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="qmovie-h.html">qmovie.h</a>>#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="qlabel-h.html">qlabel.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="qpushbutton-h.html">qpushbutton.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="qobjectlist-h.html">qobjectlist.h</a>>#include <<a href="qvbox-h.html">qvbox.h</a>>#include "filesave.xpm"#include "fileopen.xpm"#include "fileprint.xpm"const char * fileOpenText = "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.";<a name="f534"></a>ApplicationWindow::ApplicationWindow() : <a href="qmainwindow.html">QMainWindow</a>( 0, "example application main window", WDestructiveClose ){ int id; <a href="qpixmap.html">QPixmap</a> openIcon, saveIcon; fileTools = new <a href="qtoolbar.html">QToolBar</a>( this, "file operations" ); <a href="qmainwindow.html#addToolBar">addToolBar</a>( fileTools, tr( "File Operations" ), DockTop, TRUE ); 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(load()), 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" );#ifndef QT_NO_PRINTER printer = new <a href="qprinter.html">QPrinter</a>; <a href="qpixmap.html">QPixmap</a> printIcon; printIcon = QPixmap( fileprint ); QToolButton * filePrint = new <a href="qtoolbutton.html">QToolButton</a>( printIcon, "Print File", QString::null, this, SLOT(print()), fileTools, "print file" );<a name="x2044"></a> QWhatsThis::<a href="qwhatsthis.html#add">add</a>( filePrint, filePrintText );#endif (void)QWhatsThis::whatsThisButton( fileTools ); QWhatsThis::<a href="qwhatsthis.html#add">add</a>( fileOpen, fileOpenText ); QWhatsThis::<a href="qwhatsthis.html#add">add</a>( fileSave, fileSaveText ); <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 );<a name="x2013"></a> file-><a href="qmenudata.html#insertItem">insertItem</a>( "&New", this, SLOT(newDoc()), CTRL+Key_N ); id = file-><a href="qmenudata.html#insertItem">insertItem</a>( openIcon, "&Open...", this, SLOT(load()), CTRL+Key_O );<a name="x2018"></a> file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileOpenText ); id = file-><a href="qmenudata.html#insertItem">insertItem</a>( saveIcon, "&Save", this, SLOT(save()), CTRL+Key_S ); file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText ); id = file-><a href="qmenudata.html#insertItem">insertItem</a>( "Save &As...", this, SLOT(saveAs()) ); file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, fileSaveText );#ifndef QT_NO_PRINTER<a name="x2014"></a> file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>(); id = file-><a href="qmenudata.html#insertItem">insertItem</a>( printIcon, "&Print...", this, SLOT(print()), CTRL+Key_P ); file-><a href="qmenudata.html#setWhatsThis">setWhatsThis</a>( id, filePrintText );#endif file-><a href="qmenudata.html#insertSeparator">insertSeparator</a>(); file-><a href="qmenudata.html#insertItem">insertItem</a>( "&Close", this, SLOT(closeWindow()), CTRL+Key_W );<a name="x2004"></a> file-><a href="qmenudata.html#insertItem">insertItem</a>( "&Quit", qApp, SLOT( <a href="qapplication.html#closeAllWindows">closeAllWindows</a>() ), CTRL+Key_Q ); windowsMenu = new <a href="qpopupmenu.html">QPopupMenu</a>( this );<a name="x2032"></a> windowsMenu-><a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );<a name="x2031"></a> <a href="qobject.html#connect">connect</a>( windowsMenu, SIGNAL( <a href="qpopupmenu.html#aboutToShow">aboutToShow</a>() ), this, SLOT( windowsMenuAboutToShow() ) ); <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Windows", windowsMenu ); <a href="qmainwindow.html#menuBar">menuBar</a>()->insertSeparator(); <a href="qpopupmenu.html">QPopupMenu</a> * help = new <a href="qpopupmenu.html">QPopupMenu</a>( this ); <a href="qmainwindow.html#menuBar">menuBar</a>()->insertItem( "&Help", help ); help-><a href="qmenudata.html#insertItem">insertItem</a>( "&About", this, SLOT(about()), Key_F1); help-><a href="qmenudata.html#insertItem">insertItem</a>( "About &Qt", this, SLOT(aboutQt())); help-><a href="qmenudata.html#insertSeparator">insertSeparator</a>(); help-><a href="qmenudata.html#insertItem">insertItem</a>( "What's &This", this, SLOT(<a href="qmainwindow.html#whatsThis">whatsThis</a>()), SHIFT+Key_F1); <a href="qvbox.html">QVBox</a>* vb = new <a href="qvbox.html">QVBox</a>( this ); vb-><a href="qframe.html#setFrameStyle">setFrameStyle</a>( QFrame::StyledPanel | QFrame::Sunken ); ws = new <a href="qworkspace.html">QWorkspace</a>( vb );<a name="x2061"></a> ws-><a href="qworkspace.html#setScrollBarsEnabled">setScrollBarsEnabled</a>( TRUE ); <a href="qmainwindow.html#setCentralWidget">setCentralWidget</a>( vb ); <a href="qmainwindow.html#statusBar">statusBar</a>()->message( "Ready", 2000 );}ApplicationWindow::~ApplicationWindow(){#ifndef QT_NO_PRINTER delete printer;#endif}MDIWindow* <a name="f535"></a>ApplicationWindow::newDoc(){ MDIWindow* w = new MDIWindow( ws, 0, WDestructiveClose ); <a href="qobject.html#connect">connect</a>( w, SIGNAL( message(const <a href="qstring.html">QString</a>&, int) ), statusBar(), SLOT( message(const <a href="qstring.html">QString</a>&, int )) ); w-><a href="qwidget.html#setCaption">setCaption</a>("unnamed document");<a name="x2053"></a> w-><a href="qwidget.html#setIcon">setIcon</a>( QPixmap("document.xpm") ); // show the very first window in maximized mode<a name="x2063"></a> if ( ws-><a href="qworkspace.html#windowList">windowList</a>().isEmpty() )<a name="x2055"></a> w-><a href="qwidget.html#showMaximized">showMaximized</a>(); else w-><a href="qwidget.html#show">show</a>(); return w;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -