You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
326 lines
14 KiB
326 lines
14 KiB
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<!-- /home/espenr/tmp/qt-3.3.8-espenr-2499/qt-x11-free-3.3.8/examples/listbox/listbox.doc:4 -->
|
|
<html>
|
|
<head>
|
|
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
|
<title>Listbox Example</title>
|
|
<style type="text/css"><!--
|
|
fn { margin-left: 1cm; text-indent: -1cm; }
|
|
a:link { color: #004faf; text-decoration: none }
|
|
a:visited { color: #672967; text-decoration: none }
|
|
body { background: #ffffff; color: black; }
|
|
--></style>
|
|
</head>
|
|
<body>
|
|
|
|
<table border="0" cellpadding="0" cellspacing="0" width="100%">
|
|
<tr bgcolor="#E5E5E5">
|
|
<td valign=center>
|
|
<a href="index.html">
|
|
<font color="#004faf">Home</font></a>
|
|
| <a href="classes.html">
|
|
<font color="#004faf">All Classes</font></a>
|
|
| <a href="mainclasses.html">
|
|
<font color="#004faf">Main Classes</font></a>
|
|
| <a href="annotated.html">
|
|
<font color="#004faf">Annotated</font></a>
|
|
| <a href="groups.html">
|
|
<font color="#004faf">Grouped Classes</font></a>
|
|
| <a href="functions.html">
|
|
<font color="#004faf">Functions</font></a>
|
|
</td>
|
|
<td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>Listbox Example</h1>
|
|
|
|
|
|
<p>
|
|
This example shows how to use the different modes (single columns, multiple columns,
|
|
fixed number of rows, etc.) of <a href="tqlistbox.html">TQListBox</a>.
|
|
<p> <hr>
|
|
<p> Header file:
|
|
<p> <pre>/****************************************************************************
|
|
** $Id: qt/listbox.h 3.3.8 edited Jan 11 14:37 $
|
|
**
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of an example program for TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#ifndef LISTBOX_H
|
|
#define LISTBOX_H
|
|
|
|
|
|
class TQSpinBox;
|
|
class TQListBox;
|
|
class TQButtonGroup;
|
|
|
|
#include <<a href="tqwidget-h.html">tqwidget.h</a>>
|
|
|
|
|
|
class ListBoxDemo: public <a href="tqwidget.html">TQWidget</a>
|
|
{
|
|
<a href="metaobjects.html#TQ_OBJECT">TQ_OBJECT</a>
|
|
public:
|
|
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="tqlistbox.html">TQListBox</a> * l;
|
|
<a href="tqspinbox.html">TQSpinBox</a> * columns;
|
|
<a href="tqspinbox.html">TQSpinBox</a> * rows;
|
|
<a href="tqbuttongroup.html">TQButtonGroup</a> * bg;
|
|
};
|
|
|
|
|
|
#endif
|
|
</pre>
|
|
|
|
<p> <hr>
|
|
<p> Implementation:
|
|
<p> <pre>/****************************************************************************
|
|
** $Id: qt/listbox.cpp 3.3.8 edited Jan 11 14:37 $
|
|
**
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of an example program for TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#include "listbox.h"
|
|
|
|
#include <<a href="tqlabel-h.html">tqlabel.h</a>>
|
|
#include <<a href="tqradiobutton-h.html">tqradiobutton.h</a>>
|
|
#include <<a href="tqcheckbox-h.html">tqcheckbox.h</a>>
|
|
#include <<a href="tqspinbox-h.html">tqspinbox.h</a>>
|
|
#include <<a href="tqlistbox-h.html">tqlistbox.h</a>>
|
|
#include <<a href="tqbuttongroup-h.html">tqbuttongroup.h</a>>
|
|
#include <<a href="tqlayout-h.html">tqlayout.h</a>>
|
|
#include <<a href="tqpushbutton-h.html">tqpushbutton.h</a>>
|
|
|
|
|
|
<a name="f441"></a>ListBoxDemo::ListBoxDemo()
|
|
: <a href="tqwidget.html">TQWidget</a>( 0, 0 )
|
|
{
|
|
<a href="tqgridlayout.html">TQGridLayout</a> * g = new <a href="tqgridlayout.html">TQGridLayout</a>( this, 2, 2, 6 );
|
|
|
|
g-><a href="tqgridlayout.html#addWidget">addWidget</a>( new <a href="tqlabel.html">TQLabel</a>( "<b>Configuration:</b>", this ), 0, 0 );
|
|
g-><a href="tqgridlayout.html#addWidget">addWidget</a>( new <a href="tqlabel.html">TQLabel</a>( "<b>Result:</b>", this ), 0, 1 );
|
|
|
|
l = new <a href="tqlistbox.html">TQListBox</a>( this );
|
|
g-><a href="tqgridlayout.html#addWidget">addWidget</a>( l, 1, 1 );
|
|
<a name="x1447"></a> l-><a href="tqwidget.html#setFocusPolicy">setFocusPolicy</a>( TQWidget::StrongFocus );
|
|
|
|
<a href="tqvboxlayout.html">TQVBoxLayout</a> * v = new <a href="tqvboxlayout.html">TQVBoxLayout</a>;
|
|
<a name="x1430"></a> g-><a href="tqgridlayout.html#addLayout">addLayout</a>( v, 1, 0 );
|
|
|
|
<a href="tqradiobutton.html">TQRadioButton</a> * b;
|
|
bg = new <a href="tqbuttongroup.html">TQButtonGroup</a>( 0 );
|
|
|
|
b = new <a href="tqradiobutton.html">TQRadioButton</a>( "Fixed number of columns,\n"
|
|
"as many rows as needed.",
|
|
this );
|
|
<a name="x1428"></a> bg-><a href="tqbuttongroup.html#insert">insert</a>( b );
|
|
<a name="x1425"></a> v-><a href="tqboxlayout.html#addWidget">addWidget</a>( b );
|
|
<a name="x1440"></a> b-><a href="tqradiobutton.html#setChecked">setChecked</a>( TRUE );
|
|
<a name="x1426"></a> <a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="tqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setNumCols()) );
|
|
<a href="tqhboxlayout.html">TQHBoxLayout</a> * h = new <a href="tqhboxlayout.html">TQHBoxLayout</a>;
|
|
<a name="x1422"></a> v-><a href="tqboxlayout.html#addLayout">addLayout</a>( h );
|
|
<a name="x1423"></a> h-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 30 );
|
|
h-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 100 );
|
|
h-><a href="tqboxlayout.html#addWidget">addWidget</a>( new <a href="tqlabel.html">TQLabel</a>( "Columns:", this ) );
|
|
columns = new <a href="tqspinbox.html">TQSpinBox</a>( this );
|
|
h-><a href="tqboxlayout.html#addWidget">addWidget</a>( columns );
|
|
|
|
v-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 12 );
|
|
|
|
b = new <a href="tqradiobutton.html">TQRadioButton</a>( "As many columns as fit on-screen,\n"
|
|
"as many rows as needed.",
|
|
this );
|
|
bg-><a href="tqbuttongroup.html#insert">insert</a>( b );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( b );
|
|
<a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="tqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setColsByWidth()) );
|
|
|
|
v-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 12 );
|
|
|
|
b = new <a href="tqradiobutton.html">TQRadioButton</a>( "Fixed number of rows,\n"
|
|
"as many columns as needed.",
|
|
this );
|
|
bg-><a href="tqbuttongroup.html#insert">insert</a>( b );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( b );
|
|
<a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="tqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setNumRows()) );
|
|
h = new <a href="tqhboxlayout.html">TQHBoxLayout</a>;
|
|
v-><a href="tqboxlayout.html#addLayout">addLayout</a>( h );
|
|
h-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 30 );
|
|
h-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 100 );
|
|
h-><a href="tqboxlayout.html#addWidget">addWidget</a>( new <a href="tqlabel.html">TQLabel</a>( "Rows:", this ) );
|
|
rows = new <a href="tqspinbox.html">TQSpinBox</a>( this );
|
|
<a name="x1442"></a> rows-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
h-><a href="tqboxlayout.html#addWidget">addWidget</a>( rows );
|
|
|
|
v-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 12 );
|
|
|
|
b = new <a href="tqradiobutton.html">TQRadioButton</a>( "As many rows as fit on-screen,\n"
|
|
"as many columns as needed.",
|
|
this );
|
|
bg-><a href="tqbuttongroup.html#insert">insert</a>( b );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( b );
|
|
<a href="tqobject.html#connect">connect</a>( b, TQ_SIGNAL(<a href="tqbutton.html#clicked">clicked</a>()), this, TQ_SLOT(setRowsByHeight()) );
|
|
|
|
v-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 12 );
|
|
|
|
<a href="tqcheckbox.html">TQCheckBox</a> * cb = new <a href="tqcheckbox.html">TQCheckBox</a>( "Variable-height rows", this );
|
|
<a name="x1429"></a> cb-><a href="tqcheckbox.html#setChecked">setChecked</a>( TRUE );
|
|
<a name="x1427"></a> <a href="tqobject.html#connect">connect</a>( cb, TQ_SIGNAL(<a href="tqbutton.html#toggled">toggled</a>(bool)), this, TQ_SLOT(setVariableHeight(bool)) );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( cb );
|
|
v-><a href="tqboxlayout.html#addSpacing">addSpacing</a>( 6 );
|
|
|
|
cb = new <a href="tqcheckbox.html">TQCheckBox</a>( "Variable-width columns", this );
|
|
<a href="tqobject.html#connect">connect</a>( cb, TQ_SIGNAL(<a href="tqbutton.html#toggled">toggled</a>(bool)), this, TQ_SLOT(setVariableWidth(bool)) );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( cb );
|
|
|
|
cb = new <a href="tqcheckbox.html">TQCheckBox</a>( "Extended-Selection", this );
|
|
<a href="tqobject.html#connect">connect</a>( cb, TQ_SIGNAL(<a href="tqbutton.html#toggled">toggled</a>(bool)), this, TQ_SLOT(setMultiSelection(bool)) );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( cb );
|
|
|
|
<a href="tqpushbutton.html">TQPushButton</a> *pb = new <a href="tqpushbutton.html">TQPushButton</a>( "Sort ascending", this );
|
|
<a href="tqobject.html#connect">connect</a>( pb, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( sortAscending() ) );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( pb );
|
|
|
|
pb = new <a href="tqpushbutton.html">TQPushButton</a>( "Sort descending", this );
|
|
<a href="tqobject.html#connect">connect</a>( pb, TQ_SIGNAL( <a href="tqbutton.html#clicked">clicked</a>() ), this, TQ_SLOT( sortDescending() ) );
|
|
v-><a href="tqboxlayout.html#addWidget">addWidget</a>( pb );
|
|
|
|
<a name="x1424"></a> v-><a href="tqboxlayout.html#addStretch">addStretch</a>( 100 );
|
|
|
|
int i = 0;
|
|
while( ++i <= 2560 )
|
|
<a name="x1446"></a><a name="x1433"></a> l-><a href="tqlistbox.html#insertItem">insertItem</a>( TQString::<a href="tqstring.html#fromLatin1">fromLatin1</a>( "Item " ) + TQString::number( i ),
|
|
i );
|
|
<a name="x1441"></a> columns-><a href="tqrangecontrol.html#setRange">setRange</a>( 1, 256 );
|
|
<a name="x1443"></a> columns-><a href="tqspinbox.html#setValue">setValue</a>( 1 );
|
|
rows-><a href="tqrangecontrol.html#setRange">setRange</a>( 1, 256 );
|
|
rows-><a href="tqspinbox.html#setValue">setValue</a>( 256 );
|
|
|
|
<a name="x1445"></a> <a href="tqobject.html#connect">connect</a>( columns, TQ_SIGNAL(<a href="tqspinbox.html#valueChanged">valueChanged</a>(int)), this, TQ_SLOT(setNumCols()) );
|
|
<a href="tqobject.html#connect">connect</a>( rows, TQ_SIGNAL(<a href="tqspinbox.html#valueChanged">valueChanged</a>(int)), this, TQ_SLOT(setNumRows()) );
|
|
}
|
|
|
|
|
|
ListBoxDemo::~ListBoxDemo()
|
|
{
|
|
delete bg;
|
|
}
|
|
|
|
|
|
void <a name="f442"></a>ListBoxDemo::setNumRows()
|
|
{
|
|
columns-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
rows-><a href="tqwidget.html#setEnabled">setEnabled</a>( TRUE );
|
|
<a name="x1444"></a><a name="x1435"></a> l-><a href="tqlistbox.html#setRowMode">setRowMode</a>( rows-><a href="tqspinbox.html#value">value</a>() );
|
|
}
|
|
|
|
|
|
void <a name="f443"></a>ListBoxDemo::setNumCols()
|
|
{
|
|
columns-><a href="tqwidget.html#setEnabled">setEnabled</a>( TRUE );
|
|
rows-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
<a name="x1434"></a> l-><a href="tqlistbox.html#setColumnMode">setColumnMode</a>( columns-><a href="tqspinbox.html#value">value</a>() );
|
|
}
|
|
|
|
|
|
void <a name="f444"></a>ListBoxDemo::setRowsByHeight()
|
|
{
|
|
columns-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
rows-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
l-><a href="tqlistbox.html#setRowMode">setRowMode</a>( TQListBox::FitToHeight );
|
|
}
|
|
|
|
|
|
void <a name="f445"></a>ListBoxDemo::setColsByWidth()
|
|
{
|
|
columns-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
rows-><a href="tqwidget.html#setEnabled">setEnabled</a>( FALSE );
|
|
l-><a href="tqlistbox.html#setColumnMode">setColumnMode</a>( TQListBox::FitToWidth );
|
|
}
|
|
|
|
|
|
void <a name="f446"></a>ListBoxDemo::setVariableWidth( bool b )
|
|
{
|
|
<a name="x1438"></a> l-><a href="tqlistbox.html#setVariableWidth">setVariableWidth</a>( b );
|
|
}
|
|
|
|
|
|
void <a name="f447"></a>ListBoxDemo::setVariableHeight( bool b )
|
|
{
|
|
<a name="x1437"></a> l-><a href="tqlistbox.html#setVariableHeight">setVariableHeight</a>( b );
|
|
}
|
|
|
|
void <a name="f448"></a>ListBoxDemo::setMultiSelection( bool b )
|
|
{
|
|
<a name="x1432"></a> l-><a href="tqlistbox.html#clearSelection">clearSelection</a>();
|
|
<a name="x1436"></a> l-><a href="tqlistbox.html#setSelectionMode">setSelectionMode</a>( b ? TQListBox::Extended : <a href="tqlistbox.html">TQListBox</a>::Single );
|
|
}
|
|
|
|
void <a name="f449"></a>ListBoxDemo::sortAscending()
|
|
{
|
|
<a name="x1439"></a> l-><a href="tqlistbox.html#sort">sort</a>( TRUE );
|
|
}
|
|
|
|
void <a name="f450"></a>ListBoxDemo::sortDescending()
|
|
{
|
|
l-><a href="tqlistbox.html#sort">sort</a>( FALSE );
|
|
}
|
|
</pre>
|
|
|
|
<p> <hr>
|
|
<p> Main:
|
|
<p> <pre>/****************************************************************************
|
|
** $Id: qt/main.cpp 3.3.8 edited Jan 11 14:37 $
|
|
**
|
|
** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.
|
|
**
|
|
** This file is part of an example program for TQt. This example
|
|
** program may be used, distributed and modified without limitation.
|
|
**
|
|
*****************************************************************************/
|
|
|
|
#include "listbox.h"
|
|
#include <<a href="qapplication-h.html">ntqapplication.h</a>>
|
|
|
|
int main( int argc, char **argv )
|
|
{
|
|
<a href="ntqapplication.html">TQApplication</a> a( argc, argv );
|
|
|
|
ListBoxDemo t;
|
|
t.<a href="tqwidget.html#setCaption">setCaption</a>( "TQt Example - Listbox" );
|
|
a.<a href="ntqapplication.html#setMainWidget">setMainWidget</a>( &t );
|
|
t.<a href="tqwidget.html#show">show</a>();
|
|
|
|
return a.<a href="ntqapplication.html#exec">exec</a>();
|
|
}
|
|
</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 © 2007
|
|
<a href="troll.html">Trolltech</a><td align=center><a href="trademarks.html">Trademarks</a>
|
|
<td align=right><div align=right>TQt 3.3.8</div>
|
|
</table></div></address></body>
|
|
</html>
|