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

📄 listbox-main-cpp.html

📁 qtopiaphone英文帮助,用于初学者和开发人员,初学者可以用来学习,开发人员可以用来资料查询.
💻 HTML
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Qt Toolkit - listbox/main.cpp example file</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: white; color: black; }--></style></head><body bgcolor="#ffffff"><table width="100%"><tr><td><a href="index.html"><img width="100" height="100" src="qtlogo.png"alt="Home" border="0"><img width="100"height="100" src="face.png" alt="Home" border="0"></a><td valign="top"><div align="right"><img src="dochead.png" width="472" height="27"><br><a href="classes.html"><b>Classes</b></a>- <a href="annotated.html">Annotated</a>- <a href="hierarchy.html">Tree</a>- <a href="functions.html">Functions</a>- <a href="index.html">Home</a>- <a href="topicals.html"><b>Structure</b>  <font face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular" align="center" size=32>Qte</font></a></div></table><h1 align=center>Listboxe Example</h1><br clear="all">  This example shows how to use the different modes (single columns, multipe columns,  fixed number of rows, etc.) of QListBox.  <hr>  Header file: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/listbox/listbox.h   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.*******************************************************************************/#ifndef LISTBOX_H#define LISTBOX_Hclass QSpinBox;class QListBox;class QButtonGroup;#include &lt;<a href="qwidget-h.html">qwidget.h</a>&gt;class ListBoxDemo: public QWidget{    Q_OBJECTpublic:    ListBoxDemo();    ~ListBoxDemo();private slots:    void setNumRows();    void setNumCols();    void setRowsByHeight();    void setColsByWidth();    void setVariableWidth( bool );    void setVariableHeight( bool );    void setMultiSelection( bool );    void sortAscending();    void sortDescending();private:    <a href="qlistbox.html">QListBox</a> * l;    <a href="qspinbox.html">QSpinBox</a> * columns;    <a href="qspinbox.html">QSpinBox</a> * rows;    <a href="qbuttongroup.html">QButtonGroup</a> * bg;};#endif</pre>  <hr>  Implementation: <pre>/****************************************************************************** &#36;Id&#58; qt/examples/listbox/listbox.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 "listbox.h"#include &lt;<a href="qlabel-h.html">qlabel.h</a>&gt;#include &lt;<a href="qradiobutton-h.html">qradiobutton.h</a>&gt;#include &lt;<a href="qcheckbox-h.html">qcheckbox.h</a>&gt;#include &lt;<a href="qspinbox-h.html">qspinbox.h</a>&gt;#include &lt;<a href="qlistbox-h.html">qlistbox.h</a>&gt;#include &lt;<a href="qbuttongroup-h.html">qbuttongroup.h</a>&gt;#include &lt;<a href="qlayout-h.html">qlayout.h</a>&gt;#include &lt;<a href="qpushbutton-h.html">qpushbutton.h</a>&gt;ListBoxDemo::ListBoxDemo()    : <a href="qwidget.html">QWidget</a>( 0, 0 ){    <a href="qgridlayout.html">QGridLayout</a> * g = new <a href="qgridlayout.html">QGridLayout</a>( this, 2, 2, 6 );    g-&gt;<a href="qgridlayout.html#dac29c">addWidget</a>( new QLabel( "&lt;b&gt;Configuration:&lt;/b&gt;", this ), 0, 0 );    g-&gt;<a href="qgridlayout.html#dac29c">addWidget</a>( new QLabel( "&lt;b&gt;Result:&lt;/b&gt;", this ), 0, 1 );    l = new <a href="qlistbox.html">QListBox</a>( this );    g-&gt;<a href="qgridlayout.html#dac29c">addWidget</a>( l, 1, 1 );    l-&gt;setFocusPolicy( QWidget::StrongFocus );    <a href="qvboxlayout.html">QVBoxLayout</a> * v = new <a href="qvboxlayout.html">QVBoxLayout</a>;    g-&gt;<a href="qgridlayout.html#a409bc">addLayout</a>( v, 1, 0 );    <a href="qradiobutton.html">QRadioButton</a> * b;    bg = new <a href="qbuttongroup.html">QButtonGroup</a>( 0 );    b = new <a href="qradiobutton.html">QRadioButton</a>( "Fixed number of columns,\n"                          "as many rows as needed.",                          this );    bg-&gt;insert( b );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( b );    b-&gt;<a href="qradiobutton.html#0e50fc">setChecked</a>( TRUE );    <a href="qobject.html#fbde73">connect</a>( b, SIGNAL(clicked()), this, SLOT(<a href=#67>setNumCols</a>()) );    <a href="qhboxlayout.html">QHBoxLayout</a> * h = new <a href="qhboxlayout.html">QHBoxLayout</a>;    v-&gt;<a href="qboxlayout.html#6ff301">addLayout</a>( h );    h-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 30 );    h-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 100 );    h-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( new QLabel( "Columns:", this ) );    columns = new <a href="qspinbox.html">QSpinBox</a>( this );    h-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( columns );    v-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 12 );    b = new <a href="qradiobutton.html">QRadioButton</a>( "As many columns as fit on-screen,\n"                          "as many rows as needed.",                          this );    bg-&gt;insert( b );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( b );    <a href="qobject.html#fbde73">connect</a>( b, SIGNAL(clicked()), this, SLOT(<a href=#69>setColsByWidth</a>()) );    v-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 12 );    b = new <a href="qradiobutton.html">QRadioButton</a>( "Fixed number of rows,\n"                          "as many columns as needed.",                          this );    bg-&gt;insert( b );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( b );    <a href="qobject.html#fbde73">connect</a>( b, SIGNAL(clicked()), this, SLOT(<a href=#66>setNumRows</a>()) );    h = new <a href="qhboxlayout.html">QHBoxLayout</a>;    v-&gt;<a href="qboxlayout.html#6ff301">addLayout</a>( h );    h-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 30 );    h-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 100 );    h-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( new QLabel( "Rows:", this ) );    rows = new <a href="qspinbox.html">QSpinBox</a>( this );    rows-&gt;setEnabled( FALSE );    h-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( rows );    v-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 12 );    b = new <a href="qradiobutton.html">QRadioButton</a>( "As many rows as fit on-screen,\n"                          "as many columns as needed.",                          this );    bg-&gt;insert( b );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( b );    <a href="qobject.html#fbde73">connect</a>( b, SIGNAL(clicked()), this, SLOT(<a href=#68>setRowsByHeight</a>()) );    v-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 12 );    <a href="qcheckbox.html">QCheckBox</a> * cb = new <a href="qcheckbox.html">QCheckBox</a>( "Variable-height rows", this );    cb-&gt;<a href="qcheckbox.html#08b09c">setChecked</a>( TRUE );    <a href="qobject.html#fbde73">connect</a>( cb, SIGNAL(toggled(bool)), this, SLOT(<a href=#71>setVariableHeight</a>(bool)) );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( cb );    v-&gt;<a href="qboxlayout.html#fc3fb6">addSpacing</a>( 6 );    cb = new <a href="qcheckbox.html">QCheckBox</a>( "Variable-width columns", this );    <a href="qobject.html#fbde73">connect</a>( cb, SIGNAL(toggled(bool)), this, SLOT(<a href=#70>setVariableWidth</a>(bool)) );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( cb );    cb = new <a href="qcheckbox.html">QCheckBox</a>( "Extended-Selection", this );    <a href="qobject.html#fbde73">connect</a>( cb, SIGNAL(toggled(bool)), this, SLOT(<a href=#72>setMultiSelection</a>(bool)) );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( cb );    <a href="qpushbutton.html">QPushButton</a> *pb = new <a href="qpushbutton.html">QPushButton</a>( "Sort ascending", this );    <a href="qobject.html#fbde73">connect</a>( pb, SIGNAL( clicked() ), this, SLOT( <a href=#73>sortAscending</a>() ) );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( pb );    pb = new <a href="qpushbutton.html">QPushButton</a>( "Sort descending", this );    <a href="qobject.html#fbde73">connect</a>( pb, SIGNAL( clicked() ), this, SLOT( <a href=#74>sortDescending</a>() ) );    v-&gt;<a href="qboxlayout.html#ebba99">addWidget</a>( pb );    v-&gt;<a href="qboxlayout.html#0226eb">addStretch</a>( 100 );    int i = 0;    while( ++i &lt;= 2560 )        l-&gt;insertItem( <a href="qstring.html#0b1906">QString::fromLatin1</a>( "Item " ) + QString::number( i ),                       i );    columns-&gt;setRange( 1, 256 );    columns-&gt;setValue( 1 );    rows-&gt;setRange( 1, 256 );    rows-&gt;setValue( 256 );    <a href="qobject.html#fbde73">connect</a>( columns, SIGNAL(valueChanged(int)), this, SLOT(<a href=#67>setNumCols</a>()) );    <a href="qobject.html#fbde73">connect</a>( rows, SIGNAL(valueChanged(int)), this, SLOT(<a href=#66>setNumRows</a>()) );}ListBoxDemo::~ListBoxDemo(){    delete bg;}void <a name="66"></a>ListBoxDemo::setNumRows(){    columns-&gt;setEnabled( FALSE );    rows-&gt;setEnabled( TRUE );    l-&gt;setRowMode( rows-&gt;value() );}void <a name="67"></a>ListBoxDemo::setNumCols(){    columns-&gt;setEnabled( TRUE );    rows-&gt;setEnabled( FALSE );    l-&gt;setColumnMode( columns-&gt;value() );}void <a name="68"></a>ListBoxDemo::setRowsByHeight(){    columns-&gt;setEnabled( FALSE );    rows-&gt;setEnabled( FALSE );    l-&gt;setRowMode( QListBox::FitToHeight );}void <a name="69"></a>ListBoxDemo::setColsByWidth(){    columns-&gt;setEnabled( FALSE );    rows-&gt;setEnabled( FALSE );    l-&gt;setColumnMode( QListBox::FitToWidth );}void <a name="70"></a>ListBoxDemo::setVariableWidth( bool b ){    l-&gt;setVariableWidth( b );}void <a name="71"></a>ListBoxDemo::setVariableHeight( bool b ){    l-&gt;setVariableHeight( b );}void <a name="72"></a>ListBoxDemo::setMultiSelection( bool b ){    l-&gt;clearSelection();    l-&gt;setSelectionMode( b ? QListBox::Extended : QListBox::Single );}void <a name="73"></a>ListBoxDemo::sortAscending(){    l-&gt;sort( TRUE );}void <a name="74"></a>ListBoxDemo::sortDescending(){    l-&gt;sort( FALSE );}</pre>  <hr>  Main:<pre>/****************************************************************************** &#36;Id&#58; qt/examples/listbox/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 "listbox.h"#include &lt;<a name="qapplication.h"></a><a href="qapplication-h.html">qapplication.h</a>&gt;int main( int argc, char **argv ){    <a name="QApplication"></a><a href="qapplication.html">QApplication</a> a( argc, argv );    ListBoxDemo t;    t.<a name="setCaption"></a><a href="qwidget.html#d6a291">setCaption</a>( "Qt Example - Listbox" );    a.<a name="setMainWidget"></a><a href="qapplication.html#7ad759">setMainWidget</a>( &amp;t );    t.<a name="show"></a><a href="qwidget.html#200ee5">show</a>();    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 + -