⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 application-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 2 页
字号:
    help-&gt;<a href="qmenudata.html#deddb9">insertItem</a>( "What's &amp;This", this, SLOT(<a href="qmainwindow.html#f50ce2">whatsThis</a>()), SHIFT+Key_F1 );    e = new <a href="qmultilineedit.html">QMultiLineEdit</a>( this, "editor" );    e-&gt;setFocus();    <a href="qmainwindow.html#fce9ba">setCentralWidget</a>( e );    <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Ready", 2000 );    <a href="qwidget.html#ff9d07">resize</a>( 450, 600 );}ApplicationWindow::~ApplicationWindow(){    delete printer;}void <a name="431"></a>ApplicationWindow::newDoc(){    ApplicationWindow *ed = new ApplicationWindow;    ed-&gt;<a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Application");    ed-&gt;<a href="qmainwindow.html#eb53e3">show</a>();}void <a name="433"></a>ApplicationWindow::load(){    <a href="qstring.html">QString</a> fn = QFileDialog::getOpenFileName( QString::null, QString::null,                                               this);    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() )        <a href=#433>load</a>( fn );    else        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Loading aborted", 2000 );}void <a name="433"></a>ApplicationWindow::load( const char *fileName ){    <a href="qfile.html">QFile</a> f( fileName );    if ( !f.<a href="qfile.html#255995">open</a>( IO_ReadOnly ) )        return;    e-&gt;setAutoUpdate( FALSE );    e-&gt;clear();    <a href="qtextstream.html">QTextStream</a> t(&amp;f);    while ( !t.<a href="qtextstream.html#bb145b">eof</a>() ) {        <a href="qstring.html">QString</a> s = t.<a href="qtextstream.html#ae4af4">readLine</a>();        e-&gt;append( s );    }    f.<a href="qfile.html#64e640">close</a>();    e-&gt;setAutoUpdate( TRUE );    e-&gt;repaint();    e-&gt;setEdited( FALSE );    <a href="qwidget.html#d6a291">setCaption</a>( fileName );    <a href="qstring.html">QString</a> s;    s.<a href="qstring.html#926f67">sprintf</a>( "Loaded document %s", fileName );    <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( s, 2000 );}void <a name="434"></a>ApplicationWindow::save(){    if ( filename.isEmpty() ) {        <a href=#435>saveAs</a>();        return;    }    <a href="qstring.html">QString</a> text = e-&gt;text();    <a href="qfile.html">QFile</a> f( filename );    if ( !f.<a href="qfile.html#255995">open</a>( IO_WriteOnly ) ) {        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( <a href="qstring.html">QString</a>("Could not write to %1").arg(filename),                              2000 );        return;    }    <a href="qtextstream.html">QTextStream</a> t( &amp;f );    t &lt;&lt; text;    f.<a href="qfile.html#64e640">close</a>();    e-&gt;setEdited( FALSE );    <a href="qwidget.html#d6a291">setCaption</a>( filename );    <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( <a href="qstring.html">QString</a>( "File %1 saved" ).arg( filename ), 2000 );}void <a name="435"></a>ApplicationWindow::saveAs(){    <a href="qstring.html">QString</a> fn = QFileDialog::getSaveFileName( QString::null, QString::null,                                               this );    if ( !fn.<a href="qstring.html#c62623">isEmpty</a>() ) {        filename = fn;        <a href=#434>save</a>();    } else {        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Saving aborted", 2000 );    }}void <a name="436"></a>ApplicationWindow::print(){    const int Margin = 10;    int pageNo = 1;    if ( printer-&gt;setup(this) ) {               // printer dialog        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Printing..." );        <a href="qpainter.html">QPainter</a> p;        if( !p.<a href="qpainter.html#02ed5d">begin</a>( printer ) )            return;                             // paint on printer        p.<a href="qpainter.html#998df2">setFont</a>( e-&gt;font() );        int yPos        = 0;                    // y position for each line        <a href="qfontmetrics.html">QFontMetrics</a> fm = p.<a href="qpainter.html#73b2e5">fontMetrics</a>();        <a href="qpaintdevicemetrics.html">QPaintDeviceMetrics</a> metrics( printer ); // need width/height                                                // of printer surface        for( int i = 0 ; i &lt; e-&gt;numLines() ; i++ ) {            if ( Margin + yPos &gt; metrics.<a href="qpaintdevicemetrics.html#d4fedb">height</a>() - Margin ) {                <a href="qstring.html">QString</a> msg( "Printing (page " );                msg += QString::number( ++pageNo );                msg += ")...";                <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( msg );                printer-&gt;newPage();             // no more room on this page                yPos = 0;                       // back to top of page            }            p.<a href="qpainter.html#0f088f">drawText</a>( Margin, Margin + yPos,                        metrics.<a href="qpaintdevicemetrics.html#95eb7b">width</a>(), fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>(),                        ExpandTabs | DontClip,                        e-&gt;textLine( i ) );            yPos = yPos + fm.<a href="qfontmetrics.html#e6e380">lineSpacing</a>();        }        p.<a href="qpainter.html#365784">end</a>();                                // send job to printer        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Printing completed", 2000 );    } else {        <a href="qmainwindow.html#530937">statusBar</a>()-&gt;message( "Printing aborted", 2000 );    }}void <a name="437"></a>ApplicationWindow::closeEvent( <a href="qcloseevent.html">QCloseEvent</a>* ce ){    if ( !e-&gt;edited() ) {        ce-&gt;<a href="qcloseevent.html#7cf66f">accept</a>();        return;    }    switch( <a href="qmessagebox.html#66b7c8">QMessageBox::information</a>( this, "Qt Application Example",                                      "The document has been changed since "                                      "the last save.",                                      "Save Now", "Cancel", "Leave Anyway",                                      0, 1 ) ) {    case 0:        <a href=#434>save</a>();        ce-&gt;<a href="qcloseevent.html#7cf66f">accept</a>();        break;    case 1:    default: // just for sanity        ce-&gt;<a href="qcloseevent.html#ee1736">ignore</a>();        break;    case 2:        ce-&gt;<a href="qcloseevent.html#7cf66f">accept</a>();        break;    }}void <a name="438"></a>ApplicationWindow::about(){    <a href="qmessagebox.html#f6c3cd">QMessageBox::about</a>( this, "Qt Application Example",                        "This example demonstrates simple use of "                        "QMainWindow,\nQMenuBar and QToolBar.");}void <a name="439"></a>ApplicationWindow::aboutQt(){    <a href="qmessagebox.html#b72270">QMessageBox::aboutQt</a>( this, "Qt Application Example" );}</pre>  <hr>  Main:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/application/main.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 &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include "application.h"int main( int argc, char ** argv ) {    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );    ApplicationWindow * mw = new ApplicationWindow();    mw-&gt;<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Application" );    mw-&gt;<a name="show"></a><a href="qmainwindow.html#eb53e3">show</a>();    a.<a name="connect"></a><a href="qobject.html#fbde73">connect</a>( &amp;a, SIGNAL(lastWindowClosed()), &amp;a, SLOT(quit()) );    return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright 

⌨️ 快捷键说明

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