Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions |

# TQListBox Class Reference

The TQListBox widget provides a list of selectable, read-only items. More...

`#include <ntqlistbox.h>`

Inherits TQScrollView.

List of all member functions.

## Public Members

- TQListBox ( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )
- ~TQListBox ()
- uint count () const
- void insertStringList ( const TQStringList & list, int index = -1 )
- void insertStrList ( const TQStrList * list, int index = -1 )
- void insertStrList ( const TQStrList & list, int index = -1 )
- void insertStrList ( const char ** strings, int numStrings = -1, int index = -1 )
- void insertItem ( const TQListBoxItem * lbi, int index = -1 )
- void insertItem ( const TQListBoxItem * lbi, const TQListBoxItem * after )
- void insertItem ( const TQString & text, int index = -1 )
- void insertItem ( const TQPixmap & pixmap, int index = -1 )
- void insertItem ( const TQPixmap & pixmap, const TQString & text, int index = -1 )
- void removeItem ( int index )
- TQString text ( int index ) const
- const TQPixmap * pixmap ( int index ) const
- void changeItem ( const TQListBoxItem * lbi, int index )
- void changeItem ( const TQString & text, int index )
- void changeItem ( const TQPixmap & pixmap, int index )
- void changeItem ( const TQPixmap & pixmap, const TQString & text, int index )
- void takeItem ( const TQListBoxItem * item )
- int numItemsVisible () const
- int currentItem () const
- TQString currentText () const
- virtual void setCurrentItem ( int index )
- virtual void setCurrentItem ( TQListBoxItem * i )
- void centerCurrentItem () (obsolete)
- int topItem () const
- virtual void setTopItem ( int index )
- virtual void setBottomItem ( int index )
- long maxItemWidth () const
- enum SelectionMode { Single, Multi, Extended, NoSelection }
- virtual void setSelectionMode ( SelectionMode )
- SelectionMode selectionMode () const
- void setMultiSelection ( bool multi ) (obsolete)
- bool isMultiSelection () const (obsolete)
- virtual void setSelected ( TQListBoxItem * item, bool select )
- void setSelected ( int index, bool select )
- bool isSelected ( int i ) const
- bool isSelected ( const TQListBoxItem * i ) const
- TQListBoxItem * selectedItem () const
- TQListBoxItem * item ( int index ) const
- int index ( const TQListBoxItem * lbi ) const
- TQListBoxItem * findItem ( const TQString & text, ComparisonFlags compare = BeginsWith ) const
- void triggerUpdate ( bool doLayout )
- bool itemVisible ( int index )
- bool itemVisible ( const TQListBoxItem * item )
- enum LayoutMode { FixedNumber, FitToWidth, FitToHeight = FitToWidth, Variable }
- virtual void setColumnMode ( LayoutMode )
- virtual void setColumnMode ( int )
- virtual void setRowMode ( LayoutMode )
- virtual void setRowMode ( int )
- LayoutMode columnMode () const
- LayoutMode rowMode () const
- int numColumns () const
- int numRows () const
- bool variableWidth () const
- virtual void setVariableWidth ( bool )
- bool variableHeight () const
- virtual void setVariableHeight ( bool )
- bool autoScrollBar () const (obsolete)
- void setAutoScrollBar ( bool enable ) (obsolete)
- bool scrollBar () const (obsolete)
- void setScrollBar ( bool enable ) (obsolete)
- bool autoBottomScrollBar () const (obsolete)
- void setAutoBottomScrollBar ( bool enable ) (obsolete)
- bool bottomScrollBar () const (obsolete)
- void setBottomScrollBar ( bool enable ) (obsolete)
- int inSort ( const TQListBoxItem * lbi ) (obsolete)
- int inSort ( const TQString & text ) (obsolete)
- int cellHeight ( int i ) const (obsolete)
- int cellHeight () const (obsolete)
- int cellWidth () const (obsolete)
- int numCols () const (obsolete)
- int itemHeight ( int index = 0 ) const
- TQListBoxItem * itemAt ( const TQPoint & p ) const
- TQRect itemRect ( TQListBoxItem * item ) const
- TQListBoxItem * firstItem () const
- void sort ( bool ascending = TRUE )

## Public Slots

- void clear ()
- virtual void ensureCurrentVisible ()
- virtual void clearSelection ()
- virtual void selectAll ( bool select )
- virtual void invertSelection ()

## Signals

- void highlighted ( int index )
- void selected ( int index )
- void highlighted ( const TQString & )
- void selected ( const TQString & )
- void highlighted ( TQListBoxItem * )
- void selected ( TQListBoxItem * )
- void selectionChanged ()
- void selectionChanged ( TQListBoxItem * item )
- void currentChanged ( TQListBoxItem * item )
- void clicked ( TQListBoxItem * item )
- void clicked ( TQListBoxItem * item, const TQPoint & pnt )
- void pressed ( TQListBoxItem * item )
- void pressed ( TQListBoxItem * item, const TQPoint & pnt )
- void doubleClicked ( TQListBoxItem * item )
- void returnPressed ( TQListBoxItem * )
- void rightButtonClicked ( TQListBoxItem *, const TQPoint & )
- void rightButtonPressed ( TQListBoxItem *, const TQPoint & )
- void mouseButtonPressed ( int button, TQListBoxItem * item, const TQPoint & pos )
- void mouseButtonClicked ( int button, TQListBoxItem * item, const TQPoint & pos )
- void contextMenuRequested ( TQListBoxItem * item, const TQPoint & pos )
- void onItem ( TQListBoxItem * i )
- void onViewport ()

## Properties

- LayoutMode columnMode - the column layout mode for this list box
- uint count - the number of items in the list box (read only)
- int currentItem - the current highlighted item
- TQString currentText - the text of the current item (read only)
- bool multiSelection - whether or not the list box is in Multi selection mode (obsolete)
- int numColumns - the number of columns in the list box (read only)
- int numItemsVisible - the number of visible items (read only)
- int numRows - the number of rows in the list box (read only)
- LayoutMode rowMode - the row layout mode for this list box
- SelectionMode selectionMode - the selection mode of the list box
- int topItem - the index of an item at the top of the screen
- bool variableHeight - whether this list box has variable-height rows
- bool variableWidth - whether this list box has variable-width columns

## Protected Members

- void updateItem ( int index )
- void updateItem ( TQListBoxItem * i )
- int totalWidth () const (obsolete)
- int totalHeight () const (obsolete)
- virtual void paintCell ( TQPainter * p, int row, int col )
- void toggleCurrentItem ()
- bool isRubberSelecting () const
- void doLayout () const
- bool itemYPos ( int index, int * yPos ) const (obsolete)
- int findItem ( int yPos ) const (obsolete)

## Detailed Description

The TQListBox widget provides a list of selectable, read-only items.

This is typically a single-column list in which either no item or one item is selected, but it can also be used in many other ways.

TQListBox will add scroll bars as necessary, but it isn't intended for really big lists. If you want more than a few thousand items, it's probably better to use a different widget mainly because the scroll bars won't provide very good navigation, but also because TQListBox may become slow with huge lists. (See TQListView and TQTable for possible alternatives.)

There are a variety of selection modes described in the TQListBox::SelectionMode documentation. The default is Single selection mode, but you can change it using setSelectionMode(). (setMultiSelection() is still provided for compatibility with TQt 1.x. We recommend using setSelectionMode() in all code.)

Because TQListBox offers multiple selection it must display keyboard focus and selection state separately. Therefore there are functions both to set the selection state of an item, i.e. setSelected(), and to set which item displays keyboard focus, i.e. setCurrentItem().

The list box normally arranges its items in a single column and adds a vertical scroll bar if required. It is possible to have a different fixed number of columns (setColumnMode()), or as many columns as will fit in the list box's assigned screen space (setColumnMode(FitToWidth)), or to have a fixed number of rows (setRowMode()) or as many rows as will fit in the list box's assigned screen space (setRowMode(FitToHeight)). In all these cases TQListBox will add scroll bars, as appropriate, in at least one direction.

If multiple rows are used, each row can be as high as necessary (the normal setting), or you can request that all items will have the same height by calling setVariableHeight(FALSE). The same applies to a column's width, see setVariableWidth().

The TQListBox's items are TQListBoxItem objects. TQListBox provides methods to insert new items as strings, as pixmaps, and as TQListBoxItem * (insertItem() with various arguments), and to replace an existing item with a new string, pixmap or TQListBoxItem (changeItem() with various arguments). You can also remove items singly with removeItem() or clear() the entire list box. Note that if you create a TQListBoxItem yourself and insert it, TQListBox takes ownership of the item.

You can also create a TQListBoxItem, such as TQListBoxText or TQListBoxPixmap, with the list box as first parameter. The item will then append itself. When you delete an item it is automatically removed from the list box.

The list of items can be arbitrarily large; TQListBox will add scroll bars if necessary. TQListBox can display a single-column (the common case) or multiple-columns, and offers both single and multiple selection. TQListBox does not support multiple-column items (but TQListView and TQTable do), or tree hierarchies (but TQListView does).

The list box items can be accessed both as TQListBoxItem objects (recommended) and using integer indexes (the original TQListBox implementation used an array of strings internally, and the API still supports this mode of operation). Everything can be done using the new objects, and most things can be done using indexes.

Each item in a TQListBox contains a TQListBoxItem. One of the items can be the current item. The currentChanged() signal and the highlighted() signal are emitted when a new item becomes current, e.g. because the user clicks on it or TQListBox::setCurrentItem() is called. The selected() signal is emitted when the user double-clicks on an item or presses Enter on the current item.

If the user does not select anything, no signals are emitted and currentItem() returns -1.

A list box has WheelFocus as a default focusPolicy(), i.e. it can get keyboard focus by tabbing, clicking and through the use of the mouse wheel.

New items can be inserted using insertItem(), insertStrList() or insertStringList(). inSort() is obsolete because this method is quite inefficient. It's preferable to insert the items normally and call sort() afterwards, or to insert a sorted TQStringList().

By default, vertical and horizontal scroll bars are added and removed as necessary. setHScrollBarMode() and setVScrollBarMode() can be used to change this policy.

If you need to insert types other than strings and pixmaps, you must define new classes which inherit TQListBoxItem.

Warning: The list box assumes ownership of all list box items and will delete them when it does not need them any more.

See also TQListView, TQComboBox, TQButtonGroup, GUI Design Handbook: List Box (two sections), and Advanced Widgets.

## Member Type Documentation

### TQListBox::LayoutMode

This enum type is used to specify how TQListBox lays out its rows and columns.

- `TQListBox::FixedNumber` - There is a fixed number of rows (or columns).
- `TQListBox::FitToWidth` - There are as many columns as will fit on-screen.
- `TQListBox::FitToHeight` - There are as many rows as will fit on-screen.
- `TQListBox::Variable` - There are as many rows as are required by the column mode. (Or as many columns as required by the row mode.)

Example: When you call setRowMode( FitToHeight ), columnMode() automatically becomes Variable to accommodate the row mode you've set.

### TQListBox::SelectionMode

This enumerated type is used by TQListBox to indicate how it reacts to selection by the user.

- `TQListBox::Single` - When the user selects an item, any already-selected item becomes unselected and the user cannot unselect the selected item. This means that the user can never clear the selection, even though the selection may be cleared by the application programmer using TQListBox::clearSelection().
- `TQListBox::Multi` - When the user selects an item the selection status of that item is toggled and the other items are left alone. Also, multiple items can be selected by dragging the mouse while the left mouse button is kept pressed.
- `TQListBox::Extended` - When the user selects an item the selection is cleared and the new item selected. However, if the user presses the Ctrl key when clicking on an item, the clicked item gets toggled and all other items are left untouched. And if the user presses the Shift key while clicking on an item, all items between the current item and the clicked item get selected or unselected, depending on the state of the clicked item. Also, multiple items can be selected by dragging the mouse while the left mouse button is kept pressed.
- `TQListBox::NoSelection` - Items cannot be selected.

In other words, Single is a real single-selection list box, Multi is a real multi-selection list box, Extended is a list box in which users can select multiple items but usually want to select either just one or a range of contiguous items, and NoSelection is for a list box where the user can look but not touch.

## Member Function Documentation

### TQListBox::TQListBox ( TQWidget * parent = 0, const char * name = 0, WFlags f = 0 )

Constructs a new empty list box called name and with parent parent.

Performance is boosted by modifying the widget flags f so that only part of the TQListBoxItem children is redrawn. This may be unsuitable for custom TQListBoxItem classes, in which case WStaticContents and WNoAutoErase should be cleared immediately after construction.

See also TQWidget::clearWFlags() and TQt::WidgetFlags.

### TQListBox::~TQListBox ()

Destroys the list box. Deletes all list box items.

### bool TQListBox::autoBottomScrollBar () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns TRUE if hScrollBarMode() is Auto; otherwise returns FALSE.

### bool TQListBox::autoScrollBar () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns TRUE if vScrollBarMode() is Auto; otherwise returns FALSE.

### bool TQListBox::bottomScrollBar () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns FALSE if vScrollBarMode() is AlwaysOff; otherwise returns TRUE.

### int TQListBox::cellHeight ( int i ) const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns the item height of item i.

See also itemHeight().

### int TQListBox::cellHeight () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns the item height of the first item, item 0.

See also itemHeight().

### int TQListBox::cellWidth () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns the maximum item width.

See also maxItemWidth().

### void TQListBox::centerCurrentItem ()

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This function does exactly the same as ensureCurrentVisible()

See also TQListBox::ensureCurrentVisible().

### void TQListBox::changeItem ( const TQListBoxItem * lbi, int index )

Replaces the item at position index with lbi. If index is negative or too large, changeItem() does nothing.

The item that has been changed will become selected.

See also insertItem() and removeItem().

### void TQListBox::changeItem ( const TQString & text, int index )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Replaces the item at position index with a new list box text item with text text.

The operation is ignored if index is out of range.

See also insertItem() and removeItem().

### void TQListBox::changeItem ( const TQPixmap & pixmap, int index )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Replaces the item at position index with a new list box pixmap item with pixmap pixmap.

The operation is ignored if index is out of range.

See also insertItem() and removeItem().

### void TQListBox::changeItem ( const TQPixmap & pixmap, const TQString & text, int index )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Replaces the item at position index with a new list box pixmap item with pixmap pixmap and text text.

The operation is ignored if index is out of range.

See also insertItem() and removeItem().

### void TQListBox::clear ()`[slot]`

Deletes all the items in the list.

See also removeItem().

### void TQListBox::clearSelection ()`[virtual slot]`

Deselects all items, if possible.

Note that a Single selection list box will automatically select an item if it has keyboard focus.

Example: listbox/listbox.cpp.

### void TQListBox::clicked ( TQListBoxItem * item )`[signal]`

This signal is emitted when the user clicks any mouse button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

Note that you must not delete any TQListBoxItem objects in slots connected to this signal.

### void TQListBox::clicked ( TQListBoxItem * item, const TQPoint & pnt )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the user clicks any mouse button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

pnt is the position of the mouse cursor in the global coordinate system (TQMouseEvent::globalPos()). (If the click's press and release differs by a pixel or two, pnt is the position at release time.)

Note that you must not delete any TQListBoxItem objects in slots connected to this signal.

### LayoutMode TQListBox::columnMode () const

Returns the column layout mode for this list box. See the "columnMode" property for details.

### void TQListBox::contextMenuRequested ( TQListBoxItem * item, const TQPoint & pos )`[signal]`

This signal is emitted when the user invokes a context menu with the right mouse button or with special system keys, with item being the item under the mouse cursor or the current item, respectively.

pos is the position for the context menu in the global coordinate system.

### uint TQListBox::count () const

Returns the number of items in the list box. See the "count" property for details.

### void TQListBox::currentChanged ( TQListBoxItem * item )`[signal]`

This signal is emitted when the user makes a new item the current item. item is the new current list box item.

See also currentItem and currentItem.

### int TQListBox::currentItem () const

Returns the current highlighted item. See the "currentItem" property for details.

### TQString TQListBox::currentText () const

Returns the text of the current item. See the "currentText" property for details.

### void TQListBox::doLayout () const`[protected]`

This function does the hard layout work. You should never need to call it.

### void TQListBox::doubleClicked ( TQListBoxItem * item )`[signal]`

This signal is emitted whenever an item is double-clicked. It's emitted on the second button press, not the second button release. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

### void TQListBox::ensureCurrentVisible ()`[virtual slot]`

Ensures that the current item is visible.

### TQListBoxItem * TQListBox::findItem ( const TQString & text, ComparisonFlags compare = BeginsWith ) const

Finds the first list box item that has the text text and returns it, or returns 0 of no such item could be found. The search starts from the current item if the current item exists, otherwise it starts from the first list box item. If `ComparisonFlags` are specified in compare then these flags are used, otherwise the default is a case-insensitive, "begins with" search.

See also TQt::StringComparisonMode.

### int TQListBox::findItem ( int yPos ) const`[protected]`

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns the index of the item a point (0, yPos).

See also index() and itemAt().

### TQListBoxItem * TQListBox::firstItem () const

Returns the first item in this list box. If the list box is empty, returns 0.

### void TQListBox::highlighted ( int index )`[signal]`

This signal is emitted when the user makes a new item the current item. index is the index of the new current item.

See also currentChanged(), selected(), currentItem, and selectionChanged().

### void TQListBox::highlighted ( const TQString & )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the user makes a new item the current item and the item is (or has) a string. The argument is the text of the new current item.

See also currentChanged(), selected(), currentItem, and selectionChanged().

### void TQListBox::highlighted ( TQListBoxItem * )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the user makes a new item the current item. The argument is a pointer to the new current item.

See also currentChanged(), selected(), currentItem, and selectionChanged().

### int TQListBox::inSort ( const TQListBoxItem * lbi )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Using this method is quite inefficient. We suggest to use insertItem() for inserting and sort() afterwards.

Inserts lbi at its sorted position in the list box and returns the position.

All items must be inserted with inSort() to maintain the sorting order. inSort() treats any pixmap (or user-defined type) as lexicographically less than any string.

See also insertItem() and sort().

### int TQListBox::inSort ( const TQString & text )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Using this method is quite inefficient. We suggest to use insertItem() for inserting and sort() afterwards.

Inserts a new item of text at its sorted position in the list box and returns the position.

All items must be inserted with inSort() to maintain the sorting order. inSort() treats any pixmap (or user-defined type) as lexicographically less than any string.

See also insertItem() and sort().

### int TQListBox::index ( const TQListBoxItem * lbi ) const

Returns the index of lbi, or -1 if the item is not in this list box or lbi is 0.

See also item().

### void TQListBox::insertItem ( const TQListBoxItem * lbi, int index = -1 )

Inserts the item lbi into the list at position index.

If index is negative or larger than the number of items in the list box, lbi is inserted at the end of the list.

See also insertStrList().

Examples: i18n/mywidget.cpp, listbox/listbox.cpp, listboxcombo/listboxcombo.cpp, and tabdialog/tabdialog.cpp.

### void TQListBox::insertItem ( const TQListBoxItem * lbi, const TQListBoxItem * after )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the item lbi into the list after the item after, or at the beginning if after is 0.

See also insertStrList().

### void TQListBox::insertItem ( const TQString & text, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a new list box text item with the text text into the list at position index.

If index is negative, text is inserted at the end of the list.

See also insertStrList().

### void TQListBox::insertItem ( const TQPixmap & pixmap, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a new list box pixmap item with the pixmap pixmap into the list at position index.

If index is negative, pixmap is inserted at the end of the list.

See also insertStrList().

### void TQListBox::insertItem ( const TQPixmap & pixmap, const TQString & text, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts a new list box pixmap item with the pixmap pixmap and the text text into the list at position index.

If index is negative, pixmap is inserted at the end of the list.

See also insertStrList().

### void TQListBox::insertStrList ( const TQStrList * list, int index = -1 )

Inserts the string list list into the list at position index.

If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.

Warning: This function uses `const char *` rather than TQString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real TQStrings.

Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStringList().

### void TQListBox::insertStrList ( const TQStrList & list, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the string list list into the list at position index.

If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.

Warning: This function uses `const char *` rather than TQString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real TQStrings.

Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStringList().

### void TQListBox::insertStrList ( const char ** strings, int numStrings = -1, int index = -1 )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Inserts the numStrings strings of the array strings into the list at position index.

If index is negative, insertStrList() inserts strings at the end of the list. If index is too large, the operation is ignored.

Warning: This function uses `const char *` rather than TQString, so we recommend against using it. It is provided so that legacy code will continue to work, and so that programs that certainly will not need to handle code outside a single 8-bit locale can use it. See insertStringList() which uses real TQStrings.

Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStringList().

### void TQListBox::insertStringList ( const TQStringList & list, int index = -1 )

Inserts the string list list into the list at position index.

If index is negative, list is inserted at the end of the list. If index is too large, the operation is ignored.

Warning: This function is never significantly faster than a loop around insertItem().

See also insertItem() and insertStrList().

### void TQListBox::invertSelection ()`[virtual slot]`

Inverts the selection. Only works in Multi and Extended selection mode.

### bool TQListBox::isMultiSelection () const

Returns TRUE if or not the list box is in Multi selection mode; otherwise returns FALSE. See the "multiSelection" property for details.

### bool TQListBox::isRubberSelecting () const`[protected]`

Returns TRUE if the user is selecting items using a rubber band rectangle; otherwise returns FALSE.

### bool TQListBox::isSelected ( int i ) const

Returns TRUE if item i is selected; otherwise returns FALSE.

### bool TQListBox::isSelected ( const TQListBoxItem * i ) const

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if item i is selected; otherwise returns FALSE.

### TQListBoxItem * TQListBox::item ( int index ) const

Returns a pointer to the item at position index, or 0 if index is out of bounds.

See also index().

Example: listboxcombo/listboxcombo.cpp.

### TQListBoxItem * TQListBox::itemAt ( const TQPoint & p ) const

Returns the item at point p, specified in viewport coordinates, or a 0 if there is no item at p.

Use contentsToViewport() to convert between widget coordinates and viewport coordinates.

### int TQListBox::itemHeight ( int index = 0 ) const

Returns the height in pixels of the item with index index. index defaults to 0.

If index is too large, this function returns 0.

### TQRect TQListBox::itemRect ( TQListBoxItem * item ) const

Returns the rectangle on the screen that item occupies in viewport()'s coordinates, or an invalid rectangle if item is 0 or is not currently visible.

### bool TQListBox::itemVisible ( int index )

Returns TRUE if the item at position index is at least partly visible; otherwise returns FALSE.

### bool TQListBox::itemVisible ( const TQListBoxItem * item )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Returns TRUE if item is at least partly visible; otherwise returns FALSE.

### bool TQListBox::itemYPos ( int index, int * yPos ) const`[protected]`

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns the vertical pixel-coordinate in *yPos, of the list box item at position index in the list. Returns FALSE if the item is outside the visible area.

### long TQListBox::maxItemWidth () const

Returns the width of the widest item in the list box.

### void TQListBox::mouseButtonClicked ( int button, TQListBoxItem * item, const TQPoint & pos )`[signal]`

This signal is emitted when the user clicks mouse button button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

pos is the position of the mouse cursor in the global coordinate system (TQMouseEvent::globalPos()). (If the click's press and release differs by a pixel or two, pos is the position at release time.)

Note that you must not delete any TQListBoxItem objects in slots connected to this signal.

### void TQListBox::mouseButtonPressed ( int button, TQListBoxItem * item, const TQPoint & pos )`[signal]`

This signal is emitted when the user presses mouse button button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

pos is the position of the mouse cursor in the global coordinate system (TQMouseEvent::globalPos()).

Note that you must not delete any TQListBoxItem objects in slots connected to this signal.

### int TQListBox::numCols () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns the number of columns.

See also numColumns.

### int TQListBox::numColumns () const

Returns the number of columns in the list box. See the "numColumns" property for details.

### int TQListBox::numItemsVisible () const

Returns the number of visible items. See the "numItemsVisible" property for details.

### int TQListBox::numRows () const

Returns the number of rows in the list box. See the "numRows" property for details.

### void TQListBox::onItem ( TQListBoxItem * i )`[signal]`

This signal is emitted when the user moves the mouse cursor onto an item, similar to the TQWidget::enterEvent() function. i is the TQListBoxItem that the mouse has moved on.

### void TQListBox::onViewport ()`[signal]`

This signal is emitted when the user moves the mouse cursor from an item to an empty part of the list box.

### void TQListBox::paintCell ( TQPainter * p, int row, int col )`[virtual protected]`

Provided for compatibility with the old TQListBox. We recommend using TQListBoxItem::paint() instead.

Repaints the cell at row, col using painter p.

### const TQPixmap * TQListBox::pixmap ( int index ) const

Returns a pointer to the pixmap at position index, or 0 if there is no pixmap there.

See also text().

### void TQListBox::pressed ( TQListBoxItem * item )`[signal]`

This signal is emitted when the user presses any mouse button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

Note that you must not delete any TQListBoxItem objects in slots connected to this signal.

### void TQListBox::pressed ( TQListBoxItem * item, const TQPoint & pnt )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the user presses any mouse button. If item is not 0, the cursor is on item. If item is 0, the mouse cursor isn't on any item.

pnt is the position of the mouse cursor in the global coordinate system (TQMouseEvent::globalPos()).

Note that you must not delete any TQListBoxItem objects in slots connected to this signal.

See also mouseButtonPressed(), rightButtonPressed(), and clicked().

### void TQListBox::removeItem ( int index )

Removes and deletes the item at position index. If index is equal to currentItem(), a new item becomes current and the currentChanged() and highlighted() signals are emitted.

See also insertItem() and clear().

### void TQListBox::returnPressed ( TQListBoxItem * )`[signal]`

This signal is emitted when Enter or Return is pressed. The argument is currentItem().

### void TQListBox::rightButtonClicked ( TQListBoxItem *, const TQPoint & )`[signal]`

This signal is emitted when the right button is clicked (i.e. when it's released at the same point where it was pressed). The arguments are the relevant TQListBoxItem (may be 0) and the point in global coordinates.

### void TQListBox::rightButtonPressed ( TQListBoxItem *, const TQPoint & )`[signal]`

This signal is emitted when the right button is pressed. The arguments are the relevant TQListBoxItem (may be 0) and the point in global coordinates.

### LayoutMode TQListBox::rowMode () const

Returns the row layout mode for this list box. See the "rowMode" property for details.

### bool TQListBox::scrollBar () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns FALSE if vScrollBarMode() is AlwaysOff; otherwise returns TRUE.

### void TQListBox::selectAll ( bool select )`[virtual slot]`

In Multi and Extended modes, this function sets all items to be selected if select is TRUE, and to be unselected if select is FALSE.

In Single and NoSelection modes, this function only changes the selection status of currentItem().

### void TQListBox::selected ( int index )`[signal]`

This signal is emitted when the user double-clicks on an item or presses Enter on the current item. index is the index of the selected item.

See also currentChanged(), highlighted(), and selectionChanged().

### void TQListBox::selected ( const TQString & )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the user double-clicks on an item or presses Enter on the current item, and the item is (or has) a string. The argument is the text of the selected item.

See also currentChanged(), highlighted(), and selectionChanged().

### void TQListBox::selected ( TQListBoxItem * )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the user double-clicks on an item or presses Enter on the current item. The argument is a pointer to the new selected item.

See also currentChanged(), highlighted(), and selectionChanged().

### TQListBoxItem * TQListBox::selectedItem () const

Returns the selected item if the list box is in single-selection mode and an item is selected.

If no items are selected or the list box is in another selection mode this function returns 0.

See also setSelected() and multiSelection.

### void TQListBox::selectionChanged ()`[signal]`

This signal is emitted when the selection set of a list box changes. This signal is emitted in each selection mode. If the user selects five items by drag-selecting, TQListBox tries to emit just one selectionChanged() signal so the signal can be connected to computationally expensive slots.

See also selected() and currentItem.

### void TQListBox::selectionChanged ( TQListBoxItem * item )`[signal]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

This signal is emitted when the selection in a Single selection list box changes. item is the newly selected list box item.

See also selected() and currentItem.

### SelectionMode TQListBox::selectionMode () const

Returns the selection mode of the list box. See the "selectionMode" property for details.

### void TQListBox::setAutoBottomScrollBar ( bool enable )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

If enable is TRUE sets setHScrollBarMode() to AlwaysOn; otherwise sets setHScrollBarMode() to AlwaysOff.

### void TQListBox::setAutoScrollBar ( bool enable )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

If enable is TRUE sets setVScrollBarMode() to AlwaysOn; otherwise sets setVScrollBarMode() to AlwaysOff.

### void TQListBox::setBottomItem ( int index )`[virtual]`

Scrolls the list box so the item at position index in the list is displayed in the bottom row of the list box.

See also topItem.

### void TQListBox::setBottomScrollBar ( bool enable )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

If enable is TRUE sets setHScrollBarMode() to AlwaysOn; otherwise sets setHScrollBarMode() to AlwaysOff.

### void TQListBox::setColumnMode ( LayoutMode )`[virtual]`

Sets the column layout mode for this list box. See the "columnMode" property for details.

### void TQListBox::setColumnMode ( int )`[virtual]`

Sets the column layout mode for this list box. See the "columnMode" property for details.

### void TQListBox::setCurrentItem ( int index )`[virtual]`

Sets the current highlighted item to index. See the "currentItem" property for details.

### void TQListBox::setCurrentItem ( TQListBoxItem * i )`[virtual]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the current item to the TQListBoxItem i.

### void TQListBox::setMultiSelection ( bool multi )

Sets whether or not the list box is in Multi selection mode to multi. See the "multiSelection" property for details.

### void TQListBox::setRowMode ( LayoutMode )`[virtual]`

Sets the row layout mode for this list box. See the "rowMode" property for details.

### void TQListBox::setRowMode ( int )`[virtual]`

Sets the row layout mode for this list box. See the "rowMode" property for details.

### void TQListBox::setScrollBar ( bool enable )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

If enable is TRUE sets setVScrollBarMode() to AlwaysOn; otherwise sets setVScrollBarMode() to AlwaysOff.

### void TQListBox::setSelected ( TQListBoxItem * item, bool select )`[virtual]`

Selects item if select is TRUE or unselects it if select is FALSE, and repaints the item appropriately.

If the list box is a Single selection list box and select is TRUE, setSelected() calls setCurrentItem().

If the list box is a Single selection list box, select is FALSE, setSelected() calls clearSelection().

See also multiSelection, currentItem, clearSelection(), and currentItem.

### void TQListBox::setSelected ( int index, bool select )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

If select is TRUE the item at position index is selected; otherwise the item is deselected.

### void TQListBox::setSelectionMode ( SelectionMode )`[virtual]`

Sets the selection mode of the list box. See the "selectionMode" property for details.

### void TQListBox::setTopItem ( int index )`[virtual]`

Sets the index of an item at the top of the screen to index. See the "topItem" property for details.

### void TQListBox::setVariableHeight ( bool )`[virtual]`

Sets whether this list box has variable-height rows. See the "variableHeight" property for details.

### void TQListBox::setVariableWidth ( bool )`[virtual]`

Sets whether this list box has variable-width columns. See the "variableWidth" property for details.

### void TQListBox::sort ( bool ascending = TRUE )

If ascending is TRUE sorts the items in ascending order; otherwise sorts in descending order.

To compare the items, the text (TQListBoxItem::text()) of the items is used.

Example: listbox/listbox.cpp.

### void TQListBox::takeItem ( const TQListBoxItem * item )

Removes item from the list box and causes an update of the screen display. The item is not deleted. You should normally not need to call this function because TQListBoxItem::~TQListBoxItem() calls it. The normal way to delete an item is with `delete`.

See also TQListBox::insertItem().

### TQString TQListBox::text ( int index ) const

Returns the text at position index, or TQString::null if there is no text at that position.

See also pixmap().

### void TQListBox::toggleCurrentItem ()`[protected]`

Toggles the selection status of currentItem() and repaints if the list box is a Multi selection list box.

See also multiSelection.

### int TQListBox::topItem () const

Returns the index of an item at the top of the screen. See the "topItem" property for details.

### int TQListBox::totalHeight () const`[protected]`

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns contentsHeight().

### int TQListBox::totalWidth () const`[protected]`

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns contentsWidth().

### void TQListBox::triggerUpdate ( bool doLayout )

Ensures that a single paint event will occur at the end of the current event loop iteration. If doLayout is TRUE, the layout is also redone.

### void TQListBox::updateItem ( int index )`[protected]`

Repaints the item at position index in the list.

### void TQListBox::updateItem ( TQListBoxItem * i )`[protected]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Repaints the TQListBoxItem i.

### bool TQListBox::variableHeight () const

Returns TRUE if this list box has variable-height rows; otherwise returns FALSE. See the "variableHeight" property for details.

### bool TQListBox::variableWidth () const

Returns TRUE if this list box has variable-width columns; otherwise returns FALSE. See the "variableWidth" property for details.

## Property Documentation

### LayoutMode columnMode

This property holds the column layout mode for this list box.

setColumnMode() sets the layout mode and adjusts the number of displayed columns. The row layout mode automatically becomes Variable, unless the column mode is Variable.

See also rowMode, rowMode, and numColumns.

Set this property's value with setColumnMode() and get this property's value with columnMode().

### uint count

This property holds the number of items in the list box.

Get this property's value with count().

### int currentItem

This property holds the current highlighted item.

When setting this property, the highlighting is moved to the item and the list box scrolled as necessary.

If no item is current, currentItem() returns -1.

Set this property's value with setCurrentItem() and get this property's value with currentItem().

### TQString currentText

This property holds the text of the current item.

This is equivalent to text(currentItem()).

Get this property's value with currentText().

### bool multiSelection

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

This property holds whether or not the list box is in Multi selection mode.

Consider using the TQListBox::selectionMode property instead of this property.

When setting this property, Multi selection mode is used if set to TRUE and to Single selection mode if set to FALSE.

When getting this property, TRUE is returned if the list box is in Multi selection mode or Extended selection mode, and FALSE if it is in Single selection mode or NoSelection mode.

See also selectionMode.

Set this property's value with setMultiSelection() and get this property's value with isMultiSelection().

### int numColumns

This property holds the number of columns in the list box.

This is normally 1, but can be different if TQListBox::columnMode or TQListBox::rowMode has been set.

See also columnMode, rowMode, and numRows.

Get this property's value with numColumns().

### int numItemsVisible

This property holds the number of visible items.

Both partially and entirely visible items are counted.

Get this property's value with numItemsVisible().

### int numRows

This property holds the number of rows in the list box.

This is equal to the number of items in the default single-column layout, but can be different.

See also columnMode, rowMode, and numColumns.

Get this property's value with numRows().

### LayoutMode rowMode

This property holds the row layout mode for this list box.

This property is normally Variable.

setRowMode() sets the layout mode and adjusts the number of displayed rows. The column layout mode automatically becomes Variable, unless the row mode is Variable.

See also columnMode.

Set this property's value with setRowMode() and get this property's value with rowMode().

### SelectionMode selectionMode

This property holds the selection mode of the list box.

Sets the list box's selection mode, which may be one of Single (the default), Extended, Multi or NoSelection.

See also SelectionMode.

Set this property's value with setSelectionMode() and get this property's value with selectionMode().

### int topItem

This property holds the index of an item at the top of the screen.

When getting this property and the listbox has multiple columns, an arbitrary item is selected and returned.

When setting this property, the list box is scrolled so the item at position index in the list is displayed in the top row of the list box.

Set this property's value with setTopItem() and get this property's value with topItem().

### bool variableHeight

This property holds whether this list box has variable-height rows.

When the list box has variable-height rows (the default), each row is as high as the highest item in that row. When it has same-sized rows, all rows are as high as the highest item in the list box.

See also variableWidth.

Set this property's value with setVariableHeight() and get this property's value with variableHeight().

### bool variableWidth

This property holds whether this list box has variable-width columns.

When the list box has variable-width columns, each column is as wide as the widest item in that column. When it has same-sized columns (the default), all columns are as wide as the widest item in the list box.

See also variableHeight.

Set this property's value with setVariableWidth() and get this property's value with variableWidth().

This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.