A MDI ApplicationThis example program is just like the application example, but designed as Multiple Document Interface (MDI). Header file: /**************************************************************************** ** $Id: //depot/qt/main/tests/mdi/application.h#4 $ ** ** 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 <qmainwindow.h> #include <qlist.h> class QMultiLineEdit; class QToolBar; class QPopupMenu; class QWorkspace; class QPopupMenu; class QMovie; class MDIWindow: public QMainWindow { Q_OBJECT public: MDIWindow( QWidget* parent, const char* name, int wflags ); ~MDIWindow(); void load( const QString& fn ); void save(); void saveAs(); void print( QPrinter* ); signals: void message(const QString&, int ); private: QMultiLineEdit* medit; QMovie * mmovie; QString filename; }; class ApplicationWindow: public QMainWindow { Q_OBJECT public: ApplicationWindow(); ~ApplicationWindow(); private slots: MDIWindow* newDoc(); void load(); void save(); void saveAs(); void print(); void closeWindow(); void about(); void aboutQt(); void windowsMenuAboutToShow(); void windowsMenuActivated( int id ); private: QPrinter *printer; QWorkspace* ws; QToolBar *fileTools; QPopupMenu* windowsMenu; }; #endif Implementation: /**************************************************************************** ** $Id: //depot/qt/main/tests/mdi/application.cpp#7 $ ** ** 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 <qworkspace.h> #include <qimage.h> #include <qpixmap.h> #include <qtoolbar.h> #include <qtoolbutton.h> #include <qpopupmenu.h> #include <qmenubar.h> #include <qkeycode.h> #include <qmovie.h> #include <qmultilineedit.h> #include <qfile.h> #include <qfiledialog.h> #include <qlabel.h> #include <qstatusbar.h> #include <qmessagebox.h> #include <qprinter.h> #include <qapplication.h> #include <qpushbutton.h> #include <qaccel.h> #include <qtextstream.h> #include <qpainter.h> #include <qpaintdevicemetrics.h> #include <qwhatsthis.h> #include <qobjectlist.h> #include <qvbox.h> #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."; ApplicationWindow::ApplicationWindow() : QMainWindow( 0, "example application main window", WDestructiveClose ) { int id; QPixmap openIcon, saveIcon; fileTools = new QToolBar( this, "file operations" ); addToolBar( fileTools, tr( "File Operations" ), Top, TRUE ); openIcon = QPixmap( fileopen ); QToolButton * fileOpen = new QToolButton( openIcon, "Open File", QString::null, this, SLOT(load()), fileTools, "open file" ); saveIcon = QPixmap( filesave ); QToolButton * fileSave = new QToolButton( saveIcon, "Save File", QString::null, this, SLOT(save()), fileTools, "save file" ); #ifndef QT_NO_PRINTER printer = new QPrinter; QPixmap printIcon; printIcon = QPixmap( fileprint ); QToolButton * filePrint = new QToolButton( printIcon, "Print File", QString::null, this, SLOT(print()), fileTools, "print file" ); QWhatsThis::add( filePrint, filePrintText ); #endif (void)QWhatsThis::whatsThisButton( fileTools ); QWhatsThis::add( fileOpen, fileOpenText ); QWhatsThis::add( fileSave, fileSaveText ); QPopupMenu * file = new QPopupMenu( this ); menuBar()->insertItem( "&File", file ); file->insertItem( "&New", this, SLOT(newDoc()), CTRL+Key_N ); id = file->insertItem( openIcon, "&Open", this, SLOT(load()), CTRL+Key_O ); file->setWhatsThis( id, fileOpenText ); id = file->insertItem( saveIcon, "&Save", this, SLOT(save()), CTRL+Key_S ); file->setWhatsThis( id, fileSaveText ); id = file->insertItem( "Save &as...", this, SLOT(saveAs()) ); file->setWhatsThis( id, fileSaveText ); #ifndef QT_NO_PRINTER file->insertSeparator(); id = file->insertItem( printIcon, "&Print", this, SLOT(print()), CTRL+Key_P ); file->setWhatsThis( id, filePrintText ); #endif file->insertSeparator(); file->insertItem( "&Close", this, SLOT(closeWindow()), CTRL+Key_W ); file->insertItem( "&Quit", qApp, SLOT( closeAllWindows() ), CTRL+Key_Q ); windowsMenu = new QPopupMenu( this ); windowsMenu->setCheckable( TRUE ); connect( windowsMenu, SIGNAL( aboutToShow() ), this, SLOT( windowsMenuAboutToShow() ) ); menuBar()->insertItem( "&Windows", windowsMenu ); menuBar()->insertSeparator(); QPopupMenu * help = new QPopupMenu( this ); menuBar()->insertItem( "&Help", help ); help->insertItem( "&About", this, SLOT(about()), Key_F1); help->insertItem( "About &Qt", this, SLOT(aboutQt())); help->insertSeparator(); help->insertItem( "What's &This", this, SLOT(whatsThis()), SHIFT+Key_F1); QVBox* vb = new QVBox( this ); vb->setFrameStyle( QFrame::StyledPanel | QFrame::Sunken ); ws = new QWorkspace( vb ); setCentralWidget( vb ); statusBar()->message( "Ready", 2000 ); } ApplicationWindow::~ApplicationWindow() { #ifndef QT_NO_PRINTER delete printer; #endif } MDIWindow* Main: /**************************************************************************** ** $Id: //depot/qt/main/tests/mdi/main.cpp#1 $ ** ** 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 < |
Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. | Qt 2.3 | |
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD. | ||
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP ! |
Copyright © 2000-2012 - www.developpez.com