mainwindow.cpp Example File | Qt 4.8 (original) (raw)
help/simpletextviewer/mainwindow.cpp
#include <QtCore/QLibraryInfo> #include <QtGui/QApplication> #include <QtGui/QAction> #include <QtGui/QMenu> #include <QtGui/QMenuBar> #include <QtGui/QMessageBox>
#include "mainwindow.h" #include "findfiledialog.h" #include "assistant.h" #include "textedit.h"
MainWindow::MainWindow() { assistant = new Assistant;
textViewer = new TextEdit;
textViewer->setContents([QLibraryInfo](qlibraryinfo.html)::location([QLibraryInfo](qlibraryinfo.html)::ExamplesPath)
+ QLatin1String("/help/simpletextviewer/documentation/intro.html"));
setCentralWidget(textViewer);
createActions();
createMenus();
setWindowTitle(tr("Simple Text Viewer"));
resize(750, 400);}
void MainWindow::closeEvent(QCloseEvent *) { delete assistant; }
void MainWindow::about() { QMessageBox::about(this, tr("About Simple Text Viewer"), tr("This example demonstrates how to use\n" "Qt Assistant as help system for your\n" "own application.")); }
void MainWindow::showDocumentation() { assistant->showDocumentation("index.html"); }
void MainWindow::open() { FindFileDialog dialog(textViewer, assistant); dialog.exec(); }
void MainWindow::createActions() { assistantAct = new QAction(tr("Help Contents"), this); assistantAct->setShortcut(QKeySequence::HelpContents); connect(assistantAct, SIGNAL(triggered()), this, SLOT(showDocumentation()));
openAct = new [QAction](qaction.html)(tr("&Open..."), this);
openAct->setShortcut([QKeySequence](qkeysequence.html)::Open);
connect(openAct, SIGNAL(triggered()), this, SLOT(open()));
clearAct = new [QAction](qaction.html)(tr("&Clear"), this);
clearAct->setShortcut(tr("Ctrl+C"));
connect(clearAct, SIGNAL(triggered()), textViewer, SLOT(clear()));
exitAct = new [QAction](qaction.html)(tr("E&xit"), this);
exitAct->setShortcuts([QKeySequence](qkeysequence.html)::Quit);
connect(exitAct, SIGNAL(triggered()), this, SLOT(close()));
aboutAct = new [QAction](qaction.html)(tr("&About"), this);
connect(aboutAct, SIGNAL(triggered()), this, SLOT(about()));
aboutQtAct = new [QAction](qaction.html)(tr("About &Qt"), this);
connect(aboutQtAct, SIGNAL(triggered()), qApp, SLOT(aboutQt()));}
void MainWindow::createMenus() { fileMenu = new QMenu(tr("&File"), this); fileMenu->addAction(openAct); fileMenu->addAction(clearAct); fileMenu->addSeparator(); fileMenu->addAction(exitAct);
helpMenu = new [QMenu](qmenu.html)(tr("&Help"), this);
helpMenu->addAction(assistantAct);
helpMenu->addSeparator();
helpMenu->addAction(aboutAct);
helpMenu->addAction(aboutQtAct);
menuBar()->addMenu(fileMenu);
menuBar()->addMenu(helpMenu);}
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.