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

📄 customlayout-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
📖 第 1 页 / 共 3 页
字号:
    if ( st == Minimum ) {        msizeDirty = FALSE;        mcached = QSize( w, h );    } else {        sizeDirty = FALSE;        cached = QSize( w, h );    }    return;}</pre>  <hr>  Header file of the Card-Layout: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/customlayout/card.h   2.3.8   edited 2004-05-12 $**** Definition of simple flow layout for custom layout example**** Created : 979899**** Copyright (C) 1997 by 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 CARD_H#define CARD_H#include &lt;<a href="qlayout-h.html">qlayout.h</a>&gt;#include &lt;<a href="qlist-h.html">qlist.h</a>&gt;class CardLayout : public QLayout{public:    CardLayout( <a href="qwidget.html">QWidget</a> *parent, int dist )        : <a href="qlayout.html">QLayout</a>( parent, 0, dist ) {}    CardLayout( <a href="qlayout.html">QLayout</a>* parent, int dist)        : <a href="qlayout.html">QLayout</a>( parent, dist ) {}    CardLayout( int dist )        : <a href="qlayout.html">QLayout</a>( dist ) {}    ~CardLayout();    void addItem( <a href="qlayoutitem.html">QLayoutItem</a> *item );    <a href="qsize.html">QSize</a> sizeHint() const;    <a href="qsize.html">QSize</a> minimumSize() const;    <a href="qlayoutiterator.html">QLayoutIterator</a> iterator();    void setGeometry( const QRect &amp;rect );private:    <a href="qlist.html">QList</a>&lt;<a href="qlayoutitem.html">QLayoutItem</a>&gt; list;};#endif</pre>  <hr>  Implementation of the Card-Layout: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/customlayout/card.cpp   2.3.8   edited 2004-05-12 $**** Implementing your own layout: flow example**** Copyright (C) 1996 by 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 "card.h"class CardLayoutIterator :public QGLayoutIterator{public:    CardLayoutIterator( <a href="qlist.html">QList</a>&lt;<a href="qlayoutitem.html">QLayoutItem</a>&gt; *l )        : idx( 0 ), list( l )  {}    <a href="qlayoutitem.html">QLayoutItem</a> *current();    <a href="qlayoutitem.html">QLayoutItem</a> *next();    <a href="qlayoutitem.html">QLayoutItem</a> *takeCurrent();private:    int idx;    <a href="qlist.html">QList</a>&lt;<a href="qlayoutitem.html">QLayoutItem</a>&gt; *list;};<a href="qlayoutitem.html">QLayoutItem</a> *<a name="291"></a>CardLayoutIterator::current(){    return idx &lt; int( list-&gt;<a href="qlist.html#359d9f">count</a>() ) ? list-&gt;<a href="qlist.html#0e7e42">at</a>( idx ) : 0;}<a href="qlayoutitem.html">QLayoutItem</a> *<a name="292"></a>CardLayoutIterator::next(){    idx++; return current();}<a href="qlayoutitem.html">QLayoutItem</a> *<a name="293"></a>CardLayoutIterator::takeCurrent(){    return idx &lt; int( list-&gt;<a href="qlist.html#359d9f">count</a>() ) ?list-&gt;<a href="qlist.html#0639ad">take</a>( idx ) : 0;}<a href="qlayoutiterator.html">QLayoutIterator</a> <a name="294"></a>CardLayout::iterator(){    return QLayoutIterator(  new CardLayoutIterator( &amp;list )  );}CardLayout::~CardLayout(){    deleteAllItems();}void <a name="295"></a>CardLayout::addItem(  <a href="qlayoutitem.html">QLayoutItem</a> *item  ){    list.<a href="qlist.html#c5746a">append</a>( item );}void <a name="296"></a>CardLayout::setGeometry( const QRect &amp;rct ){    <a href="qlayout.html#f1f752">QLayout::setGeometry</a>( rct );    <a href="qlistiterator.html">QListIterator</a>&lt;<a href="qlayoutitem.html">QLayoutItem</a>&gt; it( list );    if ( it.<a href="qlistiterator.html#e61e8b">count</a>() == 0 )        return;    <a href="qlayoutitem.html">QLayoutItem</a> *o;    int i = 0;    int w = rct.width() - ( list.<a href="qlist.html#359d9f">count</a>() - 1 ) * spacing();    int h = rct.height() - ( list.<a href="qlist.html#359d9f">count</a>() - 1 ) * spacing();    while ( ( o=it.<a href="qlistiterator.html#e58f06">current</a>() ) != 0 ) {        ++it;        <a href="qrect.html">QRect</a> geom( rct.x() + i * spacing(), rct.y() + i * spacing(),                    w, h  );        o-&gt;<a href="qlayoutitem.html#0c6928">setGeometry</a>(  geom  );        ++i;    }}<a href="qsize.html">QSize</a> <a name="297"></a>CardLayout::sizeHint() const{    <a href="qsize.html">QSize</a> s(0,0);    int n = list.<a href="qlist.html#359d9f">count</a>();    if ( n &gt; 0 )        s = QSize(100,70); //start with a nice default size    <a href="qlistiterator.html">QListIterator</a>&lt;<a href="qlayoutitem.html">QLayoutItem</a>&gt; it(list);    <a href="qlayoutitem.html">QLayoutItem</a> *o;    while ( (o=it.<a href="qlistiterator.html#e58f06">current</a>()) != 0 ) {        ++it;        s = s.<a href="qsize.html#a74829">expandedTo</a>( o-&gt;<a href="qlayoutitem.html#83838c">minimumSize</a>() );    }    return s + n*QSize(<a href="qlayout.html#372777">spacing</a>(),<a href="qlayout.html#372777">spacing</a>());}<a href="qsize.html">QSize</a> <a name="298"></a>CardLayout::minimumSize() const{    <a href="qsize.html">QSize</a> s(0,0);    int n = list.<a href="qlist.html#359d9f">count</a>();    <a href="qlistiterator.html">QListIterator</a>&lt;<a href="qlayoutitem.html">QLayoutItem</a>&gt; it(list);    <a href="qlayoutitem.html">QLayoutItem</a> *o;    while ( (o=it.<a href="qlistiterator.html#e58f06">current</a>()) != 0 ) {        ++it;        s = s.<a href="qsize.html#a74829">expandedTo</a>( o-&gt;<a href="qlayoutitem.html#83838c">minimumSize</a>() );    }    return s + n*QSize(<a href="qlayout.html#372777">spacing</a>(),<a href="qlayout.html#372777">spacing</a>());}</pre>  <hr>  Main:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/customlayout/main.cpp   2.3.8   edited 2004-05-12 $**** Main for custom layout example**** Copyright (C) 1996 by 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 "flow.h"#include "border.h"#include "card.h"#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;#include &lt;<a name="qlabel.h"></a><a href="qlabel-h.html">qlabel.h</a>&gt;#include &lt;<a name="qcolor.h"></a><a href="qcolor-h.html">qcolor.h</a>&gt;#include &lt;<a name="qgroupbox.h"></a><a href="qgroupbox-h.html">qgroupbox.h</a>&gt;#include &lt;<a name="qpushbutton.h"></a><a href="qpushbutton-h.html">qpushbutton.h</a>&gt;#include &lt;<a name="qmultilineedit.h"></a><a href="qmultilineedit-h.html">qmultilineedit.h</a>&gt;#include &lt;<a href="qcolor-h.html">qcolor.h</a>&gt;int main( int argc, char **argv ){    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );    <a name="QWidget"></a><a href="qwidget.html">QWidget</a> *f = new <a href="qwidget.html">QWidget</a>;    <a name="QBoxLayout"></a><a href="qboxlayout.html">QBoxLayout</a> *gm = new <a name="QVBoxLayout"></a><a href="qvboxlayout.html">QVBoxLayout</a>( f, 5 );    SimpleFlow *b1 = new SimpleFlow( gm );    b1-&gt;<a name="add"></a><a href="qlayout.html#a9ddc3">add</a>( new QPushButton( "Short", f ) );    b1-&gt;<a href="qlayout.html#a9ddc3">add</a>( new QPushButton( "Longer", f ) );    b1-&gt;<a href="qlayout.html#a9ddc3">add</a>( new QPushButton( "Different text", f ) );    b1-&gt;<a href="qlayout.html#a9ddc3">add</a>( new QPushButton( "More text", f ) );    b1-&gt;<a href="qlayout.html#a9ddc3">add</a>( new QPushButton( "Even longer button text", f ) );    <a name="QPushButton"></a><a href="qpushbutton.html">QPushButton</a>* qb = new <a href="qpushbutton.html">QPushButton</a>( "Quit", f );    a.<a name="connect"></a><a href="qobject.html#fbde73">connect</a>( qb, SIGNAL( clicked() ), SLOT( quit() ) );    b1-&gt;<a href="qlayout.html#a9ddc3">add</a>( qb );    <a href="qwidget.html">QWidget</a> *wid = new <a href="qwidget.html">QWidget</a>( f );    BorderLayout *large = new BorderLayout( wid );    large-&gt;setSpacing( 5 );    large-&gt;addWidget( new QPushButton( "North", wid ), BorderLayout::North );    large-&gt;addWidget( new QPushButton( "West", wid ), BorderLayout::West );    <a name="QMultiLineEdit"></a><a href="qmultilineedit.html">QMultiLineEdit</a>* m = new <a href="qmultilineedit.html">QMultiLineEdit</a>( wid );    m-&gt;<a name="setText"></a><a href="qmultilineedit.html#3fd8c1">setText</a>( "Central\nWidget" );    large-&gt;addWidget( m, BorderLayout::Center );    <a href="qwidget.html">QWidget</a> *east1 = new <a href="qpushbutton.html">QPushButton</a>( "East", wid );    large-&gt;addWidget( east1, BorderLayout::East );    <a href="qwidget.html">QWidget</a> *east2 = new <a href="qpushbutton.html">QPushButton</a>( "East 2", wid );    large-&gt;addWidget( east2 , BorderLayout::East );    large-&gt;addWidget( new QPushButton( "South", wid ), BorderLayout::South );    //Left-to-right tab order looks better:    <a name="QWidget::setTabOrder"></a><a href="qwidget.html#20c984">QWidget::setTabOrder</a>( east2, east1 );    gm-&gt;<a name="addWidget"></a><a href="qboxlayout.html#ebba99">addWidget</a>( wid );    wid = new <a href="qwidget.html">QWidget</a>( f );    CardLayout *card = new CardLayout( wid, 10 );    <a href="qwidget.html">QWidget</a> *crd = new <a href="qwidget.html">QWidget</a>( wid );    crd-&gt;<a name="setBackgroundColor"></a><a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::red );    card-&gt;<a href="qlayout.html#a9ddc3">add</a>( crd );    crd = new <a href="qwidget.html">QWidget</a>( wid );    crd-&gt;<a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::green );    card-&gt;<a href="qlayout.html#a9ddc3">add</a>( crd );    crd = new <a href="qwidget.html">QWidget</a>( wid );    crd-&gt;<a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::blue );    card-&gt;<a href="qlayout.html#a9ddc3">add</a>( crd );    crd = new <a href="qwidget.html">QWidget</a>( wid );    crd-&gt;<a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::white );    card-&gt;<a href="qlayout.html#a9ddc3">add</a>( crd );    crd = new <a href="qwidget.html">QWidget</a>( wid );    crd-&gt;<a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::black );    card-&gt;<a href="qlayout.html#a9ddc3">add</a>( crd );    crd = new <a href="qwidget.html">QWidget</a>( wid );    crd-&gt;<a href="qwidget.html#c09181">setBackgroundColor</a>( Qt::yellow );    card-&gt;<a href="qlayout.html#a9ddc3">add</a>( crd );    gm-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( wid );    <a name="QLabel"></a><a href="qlabel.html">QLabel</a>* s = new <a href="qlabel.html">QLabel</a>( f );    s-&gt;<a name="setText"></a><a href="qlabel.html#bc5ea6">setText</a>( "outermost box" );    s-&gt;<a name="setFrameStyle"></a><a href="qframe.html#558f79">setFrameStyle</a>( QFrame::Panel | QFrame::Sunken );    s-&gt;<a name="setAlignment"></a><a href="qlabel.html#4743c8">setAlignment</a>( Qt::AlignVCenter | Qt::AlignHCenter );    gm-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( s );    a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( f );    f-&gt;<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>("Qt Example - Custom Layout");    f-&gt;<a name="show"></a><a href="qwidget.html#200ee5">show</a>();    int result = a.<a name="exec"></a><a href="qapplication.html#84c7bf">exec</a>();    delete f;    return result;}</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 + -