scrollview-scrollview-cpp.html
来自「qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人」· HTML 代码 · 共 480 行 · 第 1/2 页
HTML
480 行
<a name="QPopupMenu"></a><a href="qpopupmenu.html">QPopupMenu</a>* file = new <a href="qpopupmenu.html">QPopupMenu</a>(); CHECK_PTR( file ); menubar-><a name="insertItem"></a><a href="qmenudata.html#deddb9">insertItem</a>( "&File", file ); file-><a href="qmenudata.html#deddb9">insertItem</a>( "Quit", qApp, SLOT(quit()) ); vp_options = new <a href="qpopupmenu.html">QPopupMenu</a>(); CHECK_PTR( vp_options ); vp_options-><a name="setCheckable"></a><a href="qpopupmenu.html#672d77">setCheckable</a>( TRUE ); menubar-><a href="qmenudata.html#deddb9">insertItem</a>( "&ScrollView", vp_options ); connect( vp_options, SIGNAL(activated(int)), this, SLOT(doVPMenuItem(int)) ); vauto_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Vertical Auto" ); vaoff_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Vertical AlwaysOff" ); vaon_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Vertical AlwaysOn" ); vp_options-><a name="insertSeparator"></a><a href="qmenudata.html#e34b79">insertSeparator</a>(); hauto_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Horizontal Auto" ); haoff_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Horizontal AlwaysOff" ); haon_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Horizontal AlwaysOn" ); vp_options-><a href="qmenudata.html#e34b79">insertSeparator</a>(); corn_id = vp_options-><a href="qmenudata.html#deddb9">insertItem</a>( "cornerWidget" ); if (technique == 1) { vp = new <a href="qscrollview.html">QScrollView</a>(this); BigShrinker *bs = new BigShrinker(0);//(vp-><a name="viewport"></a><a href="qscrollview.html#26f2bf">viewport</a>()); vp-><a name="addChild"></a><a href="qscrollview.html#476636">addChild</a>(bs); bs-><a name="setAcceptDrops"></a><a href="qwidget.html#8169cb">setAcceptDrops</a>(TRUE); <a name="QObject::connect"></a><a href="qobject.html#7f8e37">QObject::connect</a>(bs, SIGNAL(clicked(int,int)), vp, SLOT(center(int,int))); } else { vp = new BigMatrix(this); if ( technique == 3 ) vp-><a name="enableClipper"></a><a href="qscrollview.html#1ed884">enableClipper</a>(TRUE); srand(1); for (int i=0; i<30; i++) { <a href="qmultilineedit.html">QMultiLineEdit</a> *l = new <a href="qmultilineedit.html">QMultiLineEdit</a>(vp-><a href="qscrollview.html#26f2bf">viewport</a>(),"First"); l-><a href="qmultilineedit.html#3fd8c1">setText</a>("Drag out more of these."); l-><a href="qwidget.html#ff9d07">resize</a>(100,100); vp-><a href="qscrollview.html#476636">addChild</a>(l, rand()%800, rand()%10000); } vp-><a href="qscrollview.html#26f2bf">viewport</a>()->setBackgroundMode(NoBackground); } f_options = new <a href="qpopupmenu.html">QPopupMenu</a>(); CHECK_PTR( f_options ); f_options-><a href="qpopupmenu.html#672d77">setCheckable</a>( TRUE ); menubar-><a href="qmenudata.html#deddb9">insertItem</a>( "&Frame", f_options ); connect( f_options, SIGNAL(activated(int)), this, SLOT(doFMenuItem(int)) ); f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "No frame", style_id ); f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Box", style_id|QFrame::Box ); f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Panel", style_id|QFrame::Panel ); f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "WinPanel", style_id|QFrame::WinPanel ); f_options-><a href="qmenudata.html#e34b79">insertSeparator</a>(); f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Plain", style_id|QFrame::Plain ); f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Raised", style_id|QFrame::Raised ); f_laststyle = f_options-><a name="indexOf"></a><a href="qmenudata.html#49862d">indexOf</a>( f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Sunken", style_id|QFrame::Sunken )); f_options-><a href="qmenudata.html#e34b79">insertSeparator</a>(); lw_options = new <a href="qpopupmenu.html">QPopupMenu</a>; CHECK_PTR( lw_options ); lw_options-><a href="qpopupmenu.html#672d77">setCheckable</a>( TRUE ); for (int lw = 1; lw <= max_lw; lw++) { <a href="qstring.html">QString</a> str; str.<a href="qstring.html#926f67">sprintf</a>("%d pixels", lw); lw_options-><a href="qmenudata.html#deddb9">insertItem</a>( str, lw_id | lw ); } f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Line width", lw_options ); connect( lw_options, SIGNAL(activated(int)), this, SLOT(doFMenuItem(int)) ); mlw_options = new <a href="qpopupmenu.html">QPopupMenu</a>; CHECK_PTR( mlw_options ); mlw_options-><a href="qpopupmenu.html#672d77">setCheckable</a>( TRUE ); for (int mlw = 0; mlw <= max_mlw; mlw++) { <a href="qstring.html">QString</a> str; str.<a href="qstring.html#926f67">sprintf</a>("%d pixels", mlw); mlw_options-><a href="qmenudata.html#deddb9">insertItem</a>( str, mlw_id | mlw ); } f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Midline width", mlw_options ); connect( mlw_options, SIGNAL(activated(int)), this, SLOT(doFMenuItem(int)) ); mw_options = new <a href="qpopupmenu.html">QPopupMenu</a>; CHECK_PTR( mw_options ); mw_options-><a href="qpopupmenu.html#672d77">setCheckable</a>( TRUE ); for (int mw = 0; mw <= max_mw; mw++) { <a href="qstring.html">QString</a> str; str.<a href="qstring.html#926f67">sprintf</a>("%d pixels", mw); mw_options-><a href="qmenudata.html#deddb9">insertItem</a>( str, mw_id | mw ); } f_options-><a href="qmenudata.html#deddb9">insertItem</a>( "Margin width", mw_options ); connect( mw_options, SIGNAL(activated(int)), this, SLOT(doFMenuItem(int)) ); setVPMenuItems(); setFMenuItems(); <a name="QVBoxLayout"></a><a href="qvboxlayout.html">QVBoxLayout</a>* vbox = new <a href="qvboxlayout.html">QVBoxLayout</a>(this); vbox-><a name="setMenuBar"></a><a href="qlayout.html#6d51f1">setMenuBar</a>(menubar); menubar-><a name="setSeparator"></a><a href="qmenubar.html#815978">setSeparator</a>(QMenuBar::InWindowsStyle); vbox-><a name="addWidget"></a><a href="qboxlayout.html#ebba99">addWidget</a>(vp); vbox-><a name="activate"></a><a href="qlayout.html#1cb33d">activate</a>(); corner = new <a name="QSizeGrip"></a><a href="qsizegrip.html">QSizeGrip</a>(this); corner-><a name="hide"></a><a href="qwidget.html#410481">hide</a>(); }private slots: void doVPMenuItem(int id) { if (id == vauto_id ) { vp-><a name="setVScrollBarMode"></a><a href="qscrollview.html#817b47">setVScrollBarMode</a>(QScrollView::Auto); } else if (id == vaoff_id) { vp-><a href="qscrollview.html#817b47">setVScrollBarMode</a>(QScrollView::AlwaysOff); } else if (id == vaon_id) { vp-><a href="qscrollview.html#817b47">setVScrollBarMode</a>(QScrollView::AlwaysOn); } else if (id == hauto_id) { vp-><a name="setHScrollBarMode"></a><a href="qscrollview.html#aaf795">setHScrollBarMode</a>(QScrollView::Auto); } else if (id == haoff_id) { vp-><a href="qscrollview.html#aaf795">setHScrollBarMode</a>(QScrollView::AlwaysOff); } else if (id == haon_id) { vp-><a href="qscrollview.html#aaf795">setHScrollBarMode</a>(QScrollView::AlwaysOn); } else if (id == corn_id) { bool corn = !vp-><a name="cornerWidget"></a><a href="qscrollview.html#37c56f">cornerWidget</a>(); vp-><a name="setCornerWidget"></a><a href="qscrollview.html#d72a9f">setCornerWidget</a>(corn ? corner : 0); } else { return; // Not for us to process. } setVPMenuItems(); } void setVPMenuItems() { <a name="QScrollView::ScrollBarMode"></a><a href="qscrollview.html#ScrollBarMode">QScrollView::ScrollBarMode</a> vm = vp-><a name="vScrollBarMode"></a><a href="qscrollview.html#8298bf">vScrollBarMode</a>(); vp_options-><a name="setItemChecked"></a><a href="qmenudata.html#319c05">setItemChecked</a>( vauto_id, vm == QScrollView::Auto ); vp_options-><a href="qmenudata.html#319c05">setItemChecked</a>( vaoff_id, vm == QScrollView::AlwaysOff ); vp_options-><a href="qmenudata.html#319c05">setItemChecked</a>( vaon_id, vm == QScrollView::AlwaysOn ); <a href="qscrollview.html#ScrollBarMode">QScrollView::ScrollBarMode</a> hm = vp-><a name="hScrollBarMode"></a><a href="qscrollview.html#e383fb">hScrollBarMode</a>(); vp_options-><a href="qmenudata.html#319c05">setItemChecked</a>( hauto_id, hm == QScrollView::Auto ); vp_options-><a href="qmenudata.html#319c05">setItemChecked</a>( haoff_id, hm == QScrollView::AlwaysOff ); vp_options-><a href="qmenudata.html#319c05">setItemChecked</a>( haon_id, hm == QScrollView::AlwaysOn ); vp_options-><a href="qmenudata.html#319c05">setItemChecked</a>( corn_id, !!vp-><a href="qscrollview.html#37c56f">cornerWidget</a>() ); } void doFMenuItem(int id) { if (id & style_id) { int sty; if (id == style_id) { sty = 0; } else if (id & QFrame::MShape) { sty = vp-><a name="frameStyle"></a><a href="qframe.html#1dc726">frameStyle</a>()&QFrame::MShadow; sty = (sty ? sty : QFrame::Plain) | (id&QFrame::MShape); } else { sty = vp-><a href="qframe.html#1dc726">frameStyle</a>()&QFrame::MShape; sty = (sty ? sty : QFrame::Box) | (id&QFrame::MShadow); } vp-><a name="setFrameStyle"></a><a href="qframe.html#558f79">setFrameStyle</a>(sty); } else if (id & lw_id) { vp-><a name="setLineWidth"></a><a href="qframe.html#b76184">setLineWidth</a>(id&~lw_id); } else if (id & mlw_id) { vp-><a name="setMidLineWidth"></a><a href="qframe.html#1e32b9">setMidLineWidth</a>(id&~mlw_id); } else { vp-><a name="setMargin"></a><a href="qframe.html#b11d00">setMargin</a>(id&~mw_id); } vp-><a name="update"></a><a href="qwidget.html#f3f721">update</a>(); setFMenuItems(); } void setFMenuItems() { int sty = vp-><a href="qframe.html#1dc726">frameStyle</a>(); f_options-><a href="qmenudata.html#319c05">setItemChecked</a>( style_id, !sty ); for (int i=1; i <= f_laststyle; i++) { int id = f_options-><a name="idAt"></a><a href="qpopupmenu.html#6776f6">idAt</a>(i); if (id & QFrame::MShape) f_options-><a href="qmenudata.html#319c05">setItemChecked</a>( id, ((id&QFrame::MShape) == (sty&QFrame::MShape)) ); else f_options-><a href="qmenudata.html#319c05">setItemChecked</a>( id, ((id&QFrame::MShadow) == (sty&QFrame::MShadow)) ); } for (int lw=1; lw<=max_lw; lw++) lw_options-><a href="qmenudata.html#319c05">setItemChecked</a>( lw_id|lw, vp-><a name="lineWidth"></a><a href="qframe.html#63cf95">lineWidth</a>() == lw ); for (int mlw=0; mlw<=max_mlw; mlw++) mlw_options-><a href="qmenudata.html#319c05">setItemChecked</a>( mlw_id|mlw, vp-><a name="midLineWidth"></a><a href="qframe.html#010489">midLineWidth</a>() == mlw ); for (int mw=0; mw<=max_mw; mw++) mw_options-><a href="qmenudata.html#319c05">setItemChecked</a>( mw_id|mw, vp-><a name="margin"></a><a href="qframe.html#cb5472">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 name="QApplication"></a><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 name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Scrollviews"); ve1.<a name="show"></a><a href="qwidget.html#200ee5">show</a>(); ve2.<a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Scrollviews"); ve2.<a href="qwidget.html#200ee5">show</a>(); ve3.<a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Scrollviews"); ve3.<a href="qwidget.html#200ee5">show</a>(); <a href="qobject.html#7f8e37">QObject::connect</a>(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit())); return a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();}#include "scrollview.moc"</pre><p><address><hr><div align="center"><table width="100%" cellspacing="0" border="0"><tr><td>Copyright
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?