scrollview-example.html

来自「QT 下载资料仅供参考」· HTML 代码 · 共 494 行 · 第 1/2 页

HTML
494
字号
        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( file );<a name="x721"></a>        menubar-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;File", file );        file-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Quit", qApp,  SLOT(<a href="qapplication.html#quit">quit</a>()) );        vp_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( vp_options );<a name="x731"></a>        vp_options-&gt;<a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );        menubar-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "&amp;ScrollView", vp_options );<a name="x729"></a>        connect( vp_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),            this, SLOT(doVPMenuItem(int)) );        vauto_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Vertical Auto" );        vaoff_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Vertical AlwaysOff" );        vaon_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Vertical AlwaysOn" );<a name="x722"></a>        vp_options-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();        hauto_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Horizontal Auto" );        haoff_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Horizontal AlwaysOff" );        haon_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Horizontal AlwaysOn" );        vp_options-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();        corn_id = vp_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "cornerWidget" );        if (technique == 1) {            vp = new <a href="qscrollview.html">QScrollView</a>(this);<a name="x742"></a>            BigShrinker *bs = new BigShrinker(0);//(vp-&gt;<a href="qscrollview.html#viewport">viewport</a>());<a name="x732"></a>            vp-&gt;<a href="qscrollview.html#addChild">addChild</a>(bs);<a name="x746"></a>            bs-&gt;<a href="qwidget.html#setAcceptDrops">setAcceptDrops</a>(TRUE);            QObject::<a href="qobject.html#connect">connect</a>(bs, SIGNAL(clicked(int,int)),<a name="x733"></a>                            vp, SLOT(<a href="qscrollview.html#center">center</a>(int,int)));        } else {            vp = new BigMatrix(this);            if ( technique == 3 )<a name="x735"></a>                vp-&gt;<a href="qscrollview.html#enableClipper">enableClipper</a>(TRUE);            srand(1);            for (int i=0; i&lt;30; i++) {                <a href="qmultilineedit.html">QMultiLineEdit</a> *l = new <a href="qmultilineedit.html">QMultiLineEdit</a>(vp-&gt;<a href="qscrollview.html#viewport">viewport</a>(),"First");                l-&gt;<a href="qtextedit.html#setText">setText</a>("Drag out more of these.");                l-&gt;<a href="qwidget.html#resize">resize</a>(100,100);                vp-&gt;<a href="qscrollview.html#addChild">addChild</a>(l, rand()%800, rand()%10000);            }            vp-&gt;<a href="qscrollview.html#viewport">viewport</a>()-&gt;setBackgroundMode(NoBackground);        }        f_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( f_options );        f_options-&gt;<a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );        menubar-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "F&amp;rame", f_options );        connect( f_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),            this, SLOT(doFMenuItem(int)) );        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "No Frame", style_id );        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Box", style_id|QFrame::Box );        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Panel", style_id|QFrame::Panel );        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "WinPanel", style_id|QFrame::WinPanel );        f_options-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Plain", style_id|QFrame::Plain );        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Raised", style_id|QFrame::Raised );<a name="x720"></a>        f_laststyle = f_options-&gt;<a href="qmenudata.html#indexOf">indexOf</a>(            f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Sunken", style_id|QFrame::Sunken ));        f_options-&gt;<a href="qmenudata.html#insertSeparator">insertSeparator</a>();        lw_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( lw_options );        lw_options-&gt;<a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );        for (int lw = 1; lw &lt;= max_lw; lw++) {            <a href="qstring.html">QString</a> str;            str.<a href="qstring.html#sprintf">sprintf</a>("%d Pixels", lw);            lw_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( str, lw_id | lw );        }        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Line Width", lw_options );        connect( lw_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),            this, SLOT(doFMenuItem(int)) );        mlw_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( mlw_options );        mlw_options-&gt;<a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );        for (int mlw = 0; mlw &lt;= max_mlw; mlw++) {            <a href="qstring.html">QString</a> str;            str.<a href="qstring.html#sprintf">sprintf</a>("%d Pixels", mlw);            mlw_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( str, mlw_id | mlw );        }        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Midline Width", mlw_options );        connect( mlw_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),            this, SLOT(doFMenuItem(int)) );        mw_options = new <a href="qpopupmenu.html">QPopupMenu</a>( menubar );        <a href="qapplication.html#Q_CHECK_PTR">Q_CHECK_PTR</a>( mw_options );        mw_options-&gt;<a href="qpopupmenu.html#setCheckable">setCheckable</a>( TRUE );        for (int mw = 0; mw &lt;= max_mw; mw++) {            <a href="qstring.html">QString</a> str;            str.<a href="qstring.html#sprintf">sprintf</a>("%d Pixels", mw);            mw_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( str, mw_id | mw );        }        f_options-&gt;<a href="qmenudata.html#insertItem">insertItem</a>( "Margin Width", mw_options );        connect( mw_options, SIGNAL(<a href="qpopupmenu.html#activated">activated</a>(int)),            this, SLOT(doFMenuItem(int)) );        setVPMenuItems();        setFMenuItems();        <a href="qvboxlayout.html">QVBoxLayout</a>* vbox = new <a href="qvboxlayout.html">QVBoxLayout</a>(this);<a name="x718"></a>        vbox-&gt;<a href="qlayout.html#setMenuBar">setMenuBar</a>(menubar);<a name="x719"></a>        menubar-&gt;<a href="qmenubar.html#setSeparator">setSeparator</a>(QMenuBar::InWindowsStyle);        vbox-&gt;<a href="qboxlayout.html#addWidget">addWidget</a>(vp);<a name="x717"></a>        vbox-&gt;<a href="qlayout.html#activate">activate</a>();        corner = new <a href="qsizegrip.html">QSizeGrip</a>(this);<a name="x745"></a>        corner-&gt;<a href="qwidget.html#hide">hide</a>();    }private slots:    void doVPMenuItem(int id)    {        if (id == vauto_id ) {<a name="x740"></a>            vp-&gt;<a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>(QScrollView::Auto);        } else if (id == vaoff_id) {            vp-&gt;<a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>(QScrollView::AlwaysOff);        } else if (id == vaon_id) {            vp-&gt;<a href="qscrollview.html#setVScrollBarMode">setVScrollBarMode</a>(QScrollView::AlwaysOn);        } else if (id == hauto_id) {<a name="x739"></a>            vp-&gt;<a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>(QScrollView::Auto);        } else if (id == haoff_id) {            vp-&gt;<a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>(QScrollView::AlwaysOff);        } else if (id == haon_id) {            vp-&gt;<a href="qscrollview.html#setHScrollBarMode">setHScrollBarMode</a>(QScrollView::AlwaysOn);        } else if (id == corn_id) {<a name="x734"></a>            bool corn = !vp-&gt;<a href="qscrollview.html#cornerWidget">cornerWidget</a>();<a name="x738"></a>            vp-&gt;<a href="qscrollview.html#setCornerWidget">setCornerWidget</a>(corn ? corner : 0);        } else {            return; // Not for us to process.        }        setVPMenuItems();    }    void setVPMenuItems()    {<a name="x741"></a>        QScrollView::ScrollBarMode vm = vp-&gt;<a href="qscrollview.html#vScrollBarMode">vScrollBarMode</a>();<a name="x723"></a>        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( vauto_id, vm == QScrollView::Auto );        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( vaoff_id, vm == QScrollView::AlwaysOff );        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( vaon_id, vm == QScrollView::AlwaysOn );<a name="x736"></a>        QScrollView::ScrollBarMode hm = vp-&gt;<a href="qscrollview.html#hScrollBarMode">hScrollBarMode</a>();        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( hauto_id, hm == QScrollView::Auto );        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( haoff_id, hm == QScrollView::AlwaysOff );        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( haon_id, hm == QScrollView::AlwaysOn );        vp_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( corn_id, !!vp-&gt;<a href="qscrollview.html#cornerWidget">cornerWidget</a>() );    }    void doFMenuItem(int id)    {        if (id &amp; style_id) {            int sty;            if (id == style_id) {                sty = 0;            } else if (id &amp; QFrame::MShape) {<a name="x709"></a>                sty = vp-&gt;<a href="qframe.html#frameStyle">frameStyle</a>()&amp;QFrame::MShadow;                sty = (sty ? sty : <a href="qframe.html">QFrame</a>::Plain) | (id&amp;QFrame::MShape);            } else {                sty = vp-&gt;<a href="qframe.html#frameStyle">frameStyle</a>()&amp;QFrame::MShape;                sty = (sty ? sty : <a href="qframe.html">QFrame</a>::Box) | (id&amp;QFrame::MShadow);            }<a name="x713"></a>            vp-&gt;<a href="qframe.html#setFrameStyle">setFrameStyle</a>(sty);        } else if (id &amp; lw_id) {<a name="x714"></a>            vp-&gt;<a href="qframe.html#setLineWidth">setLineWidth</a>(id&amp;~lw_id);        } else if (id &amp; mlw_id) {<a name="x716"></a>            vp-&gt;<a href="qframe.html#setMidLineWidth">setMidLineWidth</a>(id&amp;~mlw_id);        } else {<a name="x715"></a>            vp-&gt;<a href="qframe.html#setMargin">setMargin</a>(id&amp;~mw_id);        }<a name="x749"></a>        vp-&gt;<a href="qwidget.html#update">update</a>();        setFMenuItems();    }    void setFMenuItems()    {        int sty = vp-&gt;<a href="qframe.html#frameStyle">frameStyle</a>();        f_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( style_id, !sty );        for (int i=1; i &lt;= f_laststyle; i++) {<a name="x730"></a>            int id = f_options-&gt;<a href="qpopupmenu.html#idAt">idAt</a>(i);            if (id &amp; QFrame::MShape)                f_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( id,                    ((id&amp;QFrame::MShape) == (sty&amp;QFrame::MShape)) );            else                f_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( id,                    ((id&amp;QFrame::MShadow) == (sty&amp;QFrame::MShadow)) );        }        for (int lw=1; lw&lt;=max_lw; lw++)<a name="x710"></a>            lw_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( lw_id|lw, vp-&gt;<a href="qframe.html#lineWidth">lineWidth</a>() == lw );        for (int mlw=0; mlw&lt;=max_mlw; mlw++)<a name="x712"></a>            mlw_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( mlw_id|mlw, vp-&gt;<a href="qframe.html#midLineWidth">midLineWidth</a>() == mlw );        for (int mw=0; mw&lt;=max_mw; mw++)<a name="x711"></a>            mw_options-&gt;<a href="qmenudata.html#setItemChecked">setItemChecked</a>( mw_id|mw, vp-&gt;<a href="qframe.html#margin">margin</a>() == mw );    }private:    <a href="qscrollview.html">QScrollView</a>* vp;    <a href="qpopupmenu.html">QPopupMenu</a>* vp_options;    <a href="qpopupmenu.html">QPopupMenu</a>* f_options;    <a href="qpopupmenu.html">QPopupMenu</a>* lw_options;    <a href="qpopupmenu.html">QPopupMenu</a>* mlw_options;    <a href="qpopupmenu.html">QPopupMenu</a>* mw_options;    <a href="qsizegrip.html">QSizeGrip</a>* corner;    int vauto_id, vaoff_id, vaon_id,        hauto_id, haoff_id, haon_id,        corn_id;    int f_laststyle;};int main( int argc, char **argv ){    <a href="qapplication.html">QApplication</a> a( argc, argv );    ScrollViewExample ve1(1,0,"ve1");    ScrollViewExample ve2(2,0,"ve2");    ScrollViewExample ve3(3,0,"ve3");    ve1.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Scrollviews");    ve1.<a href="qwidget.html#show">show</a>();    ve2.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Scrollviews");    ve2.<a href="qwidget.html#show">show</a>();    ve3.<a href="qwidget.html#setCaption">setCaption</a>("Qt Example - Scrollviews");    ve3.<a href="qwidget.html#show">show</a>();    QObject::<a href="qobject.html#connect">connect</a>(qApp, SIGNAL(<a href="qapplication.html#lastWindowClosed">lastWindowClosed</a>()), qApp, SLOT(<a href="qapplication.html#quit">quit</a>()));    return a.<a href="qapplication.html#exec">exec</a>();}#include "scrollview.moc"</pre><p>See also <a href="examples.html">Examples</a>.<!-- eof --><p><address><hr><div align=center><table width=100% cellspacing=0 border=0><tr><td>Copyright &copy; 2002 <a href="http://www.trolltech.com">Trolltech</a><td><a href="http://www.trolltech.com/trademarks.html">Trademarks</a><td align=right><div align=right>Qt version 3.0.5</div></table></div></address></body></html>

⌨️ 快捷键说明

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