a:link { color: #004faf; text-decoration: none } a:visited { color: #672967; text-decoration: none }body { background: white; color: black; } -->

| Classes - Annotated - Tree - Functions - Home - Structure Qte

# QListView Class Reference

The QListView class implements a list/tree view. More...

`#include <qlistview.h>`

Inherits QScrollView.

List of all member functions.

## Public Members

- QListView ( QWidget * parent, const char * name, WFlags f )
- QListView ( QWidget * parent = 0, const char * name = 0 )
- ~QListView ()
- int treeStepSize () const
- virtual void setTreeStepSize ( int )
- virtual void insertItem ( QListViewItem * )
- virtual void takeItem ( QListViewItem * )
- virtual void removeItem ( QListViewItem * ) (obsolete)
- virtual void clear ()
- QHeader* header () const
- virtual int addColumn ( const QString & label, int size = -1 )
- virtual int addColumn ( const QIconSet & iconset, const QString & label, int size = -1 )
- void removeColumn ( int index )
- virtual void setColumnText ( int column, const QString & label )
- virtual void setColumnText ( int column, const QIconSet & iconset, const QString & label )
- QString columnText ( int column ) const
- virtual void setColumnWidth ( int column, int width )
- int columnWidth ( int column ) const
- enum WidthMode { Manual, Maximum }
- virtual void setColumnWidthMode ( int column, WidthMode )
- WidthMode columnWidthMode ( int column ) const
- int columns () const
- virtual void setColumnAlignment ( int, int )
- int columnAlignment ( int ) const
- QListViewItem* itemAt ( const QPoint & screenPos ) const
- QRect itemRect ( const QListViewItem * ) const
- int itemPos ( const QListViewItem * )
- void ensureItemVisible ( const QListViewItem * )
- void repaintItem ( const QListViewItem * ) const
- virtual void setMultiSelection ( bool enable )
- bool isMultiSelection () const
- enum SelectionMode { Single, Multi, Extended, NoSelection }
- void setSelectionMode ( SelectionMode mode )
- SelectionMode selectionMode () const
- virtual void clearSelection ()
- virtual void setSelected ( QListViewItem *, bool )
- bool isSelected ( const QListViewItem * ) const
- QListViewItem* selectedItem () const
- virtual void setOpen ( QListViewItem *, bool )
- bool isOpen ( const QListViewItem * ) const
- virtual void setCurrentItem ( QListViewItem * )
- QListViewItem* currentItem () const
- QListViewItem* firstChild () const
- int childCount () const
- virtual void setAllColumnsShowFocus ( bool )
- bool allColumnsShowFocus () const
- virtual void setItemMargin ( int )
- int itemMargin () const
- virtual void setRootIsDecorated ( bool )
- bool rootIsDecorated () const
- virtual void setSorting ( int column, bool increasing = TRUE )
- void sort ()
- virtual bool eventFilter ( QObject * o, QEvent * )
- void setShowSortIndicator ( bool show )
- bool showSortIndicator () const

## Public Slots

- void invertSelection ()
- void selectAll ( bool select )
- void triggerUpdate ()

## Signals

- void selectionChanged ()
- void selectionChanged ( QListViewItem * )
- void currentChanged ( QListViewItem * )
- void clicked ( QListViewItem * )
- void clicked ( QListViewItem *, const QPoint &, int )
- void pressed ( QListViewItem * )
- void pressed ( QListViewItem *, const QPoint &, int )
- void doubleClicked ( QListViewItem * )
- void returnPressed ( QListViewItem * )
- void rightButtonClicked ( QListViewItem *, const QPoint &, int )
- void rightButtonPressed ( QListViewItem *, const QPoint &, int )
- void mouseButtonPressed ( int, QListViewItem *, const QPoint &, int )
- void mouseButtonClicked ( int, QListViewItem *, const QPoint &, int )
- void onItem ( QListViewItem * item )
- void onViewport ()
- void expanded ( QListViewItem * item )
- void collapsed ( QListViewItem * item )

## Protected Members

- virtual void contentsMousePressEvent ( QMouseEvent * e )
- virtual void contentsMouseReleaseEvent ( QMouseEvent * e )
- virtual void contentsMouseMoveEvent ( QMouseEvent * e )
- virtual void contentsMouseDoubleClickEvent ( QMouseEvent * e )
- virtual void resizeEvent ( QResizeEvent * e )
- virtual void drawContentsOffset ( QPainter *, int ox, int oy, int cx, int cy, int cw, int ch )
- virtual void paintEmptyArea ( QPainter *, const QRect & )

## Protected Slots

- void updateContents ()
- void doAutoScroll ()

## Properties

Type | Name | READ | WRITE | Options
--- | --- | --- | --- | ---
int | columns | columns |  |
bool | multiSelection | isMultiSelection | setMultiSelection | DESIGNABLE false
SelectionMode | selectionMode | selectionMode | setSelectionMode |
int | childCount | childCount |  |
bool | allColumnsShowFocus | allColumnsShowFocus | setAllColumnsShowFocus |
bool | showSortIndicator | showSortIndicator | setShowSortIndicator |
int | itemMargin | itemMargin | setItemMargin |
bool | rootIsDecorated | rootIsDecorated | setRootIsDecorated |

## Detailed Description

The QListView class implements a list/tree view.

It can display and control a hierarchy of multi-column items, and provides the ability to add new items at any time, let the user select one or many items, sort the list in increasing or decreasing order by any column, and so on.

The simplest mode of usage is to create a QListView, add some column headers using addColumn(), create one or more QListViewItem objects with the QListView as parent, set up the list view's geometry(), and show() it.

The main setup functions are

- addColumn() - adds a column, with text and perhaps width.
- setColumnWidthMode() - sets the column to be resized automatically or not.
- setAllColumnsShowFocus() - decides whether items should show keyboard focus using all columns, or just column 0. The default is to show focus using just column 0.
- setRootIsDecorated() - decides whether root items can be opened and closed by the user, and have open/close decoration to their left. The default is FALSE.
- setTreeStepSize() - decides the how many pixels an item's children are indented relative to their parent. The default is 20. This is mostly a matter of taste.
- setSorting() - decides whether the items should be sorted, whether it should be in ascending or descending order, and by what column it should be sorted.

To handle events such as mouse-presses on the listview, derived classes can reimplement the QScrollView functions contentsMousePressEvent, contentsMouseReleaseEvent, contentsMouseDoubleClickEvent, contentsMouseMoveEvent, contentsDragEnterEvent, contentsDragMoveEvent, contentsDragLeaveEvent, contentsDropEvent, and contentsWheelEvent.

There are also several functions for mapping between items and coordinates. itemAt() returns the item at a position on-screen, itemRect() returns the rectangle an item occupies on the screen and itemPos() returns the position of any item (not on-screen, in the list view). firstChild() returns the item at the top of the view (not necessarily on-screen) so you can iterate over the items using either QListViewItem::itemBelow() or a combination of QListViewItem::firstChild() and QListViewItem::nextSibling().

Naturally, QListView provides a clear() function, as well as an explicit insertItem() for when QListViewItem's default insertion won't do.

There is a variety of selection modes, described in the QListView::SelectionMode documentation. The default is single-selection, and you can change it using setSelectionMode(). For compatibility with previous Qt versions there is still the setMultiSelection() methode. Calling setMultiSelection( TRUE ) is equivalent to setSelectionMode( Multi ), and setMultiSelection( FALSE ) is equivalent to setSelectionMode( Single ). It's suggested not to use setMultiSelection() anymore, but to use setSelectionMode() instead.

Since QListView offers multiple selection it has to display keyboard focus and selection state separately. Therefore there are functions both to set the selection state of an item, setSelected(), and to select which item displays keyboard focus, setCurrentItem().

QListView emits two groups of signals: One group signals changes in selection/focus state and one signals selection. The first group consists of selectionChanged(), applicable to all list views, and selectionChanged( QListViewItem * ), applicable only to single-selection list view, and currentChanged( QListViewItem * ). The second group consists of doubleClicked( QListViewItem * ), returnPressed( QListViewItem * ) and rightButtonClicked( QListViewItem *, const QPoint&, int ), etc.

In Motif style, QListView deviates fairly strongly from the look and feel of the Motif hierarchical tree view. This is done mostly to provide a usable keyboard interface and to make the list view look better with a white background.

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

Examples: xml/tagreader-with-features/tagreader.cpp

## Member Type Documentation

### QListView::SelectionMode

This enumerated type is used by QListView to indicate how it reacts to selection by the user. It has four values:

- `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 QListView::clearSelection().
- `Multi` - When the user selects an item in the most ordinary way, the selection status of that item is toggled and the other items are left alone.
- `Extended` - When the user selects an item in the most ordinary way, 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 stayes pressed.
- `NoSelection` - Items cannot be selected.

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

### QListView::WidthMode

This enum type describes how the width of a column in the view changes. The currently defined modes are:

- `Manual` - the column width does not change automatically
- `Maximum` - the column is automatically sized according to the widths of all items in the column. (Note: The column never shrinks in this case.) This means the column is always resized to the width of the item with the largest width in the column.

See also setColumnWidth(), setColumnWidthMode() and columnWidth().

## Member Function Documentation

### QListView::QListView ( QWidget * parent = 0, const char * name = 0 )

Constructs a new empty list view, with parent as a parent and name as object name.

Performance is boosted by modifying the widget flags so that only part of the QListViewItem children is redrawn. This may be unsuitable for custom QListViewItem classes, in which case `WNorthWestGravity` and `WRepaintNoErase` should be cleared.

See also QWidget::clearWFlags() and Qt::WidgetFlags.

### QListView::QListView ( QWidget * parent, const char * name, WFlags f )

Constructs a new empty list view, with parent as a parent and name as object name.

Performance is boosted by modifying the widget flags f so that only part of the QListViewItem children is redrawn. This may be unsuitable for custom QListViewItem classes, in which case `WNorthWestGravity` and `WRepaintNoErase` should be cleared.

See also QWidget::clearWFlags() and Qt::WidgetFlags.

### QListView::~QListView ()

Destructs the listview, deleting all items in it, and frees up all allocated resources.

### int QListView::addColumn ( const QIconSet & iconset, const QString & label, int width = -1 ) `[virtual]`

Adds a new column at the right end of the widget, with the header label and iconset, and returns the index of the column.

If width is negative, the new column will have WidthMode Maximum, otherwise it will be Manual at width pixels wide.

See also setColumnText(), setColumnWidth() and setColumnWidthMode().

### int QListView::addColumn ( const QString & label, int width = -1 ) `[virtual]`

Adds a new column at the right end of the widget, with the header label, and returns the index of the column.

If width is negative, the new column will have WidthMode Maximum, otherwise it will be Manual at width pixels wide.

See also setColumnText(), setColumnWidth() and setColumnWidthMode().

Examples: dirview/main.cpp

### bool QListView::allColumnsShowFocus () const

Returns TRUE if the items in this list view indicate focus and selection state using all of their columns, else FALSE.

See also setAllColumnsShowFocus().

### int QListView::childCount () const

Returns the current number of parentless QListViewItem objects in this QListView, like QListViewItem::childCount() returns the number of child items for a QListViewItem.

See also QListViewItem::childCount().

### void QListView::clear () `[virtual]`

Remove and delete all the items in this list view, and trigger an update.

See also triggerUpdate().

### void QListView::clearSelection () `[virtual]`

Sets all items to be not selected, updates the list view as necessary and emits the selectionChanged() signals. Note that for multi-selection list views, this function needs to iterate over all items.

See also setSelected() and setMultiSelection().

### void QListView::clicked ( QListViewItem * item ) `[signal]`

This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listview. item is the pointer to the clicked listview item or NULL, if the user didn't click on an item.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

### void QListView::clicked ( QListViewItem * item, const QPoint & pnt, int c ) `[signal]`

This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listview. item is the pointer to the clicked listview item or NULL, if the user didn't click on an item. pnt is the position where the user has clicked, and c the column into which the user clicked.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

### void QListView::collapsed ( QListViewItem * item ) `[signal]`

This signals is emitted when the item has been collapsed. This means the children of the item are hidden because the user double-clicked the item or clicked on the root decoration, or setOpen() with FALSE as argument has been called.

See also expanded().

### int QListView::columnAlignment ( int column ) const

Returns the alignment of logical column column. The default is `AlignLeft.`

See also Qt::AlignmentFlags.

### QString QListView::columnText ( int c ) const

Returns the text of column c.

### int QListView::columnWidth ( int c ) const

Returns the width of column c.

### QListView::WidthMode QListView::columnWidthMode( int c ) const

Returns the currently set WidthMode for column c.

See also setColumnWidthMode().

### int QListView::columns () const

Returns the number of columns of this list view.

See also addColumn() and removeColumn().

### void QListView::contentsMouseDoubleClickEvent ( QMouseEvent * e ) `[virtual protected]`

Processes mouse double-click events on behalf of the viewed widget.

Reimplemented from QScrollView.

### void QListView::contentsMouseMoveEvent ( QMouseEvent * e ) `[virtual protected]`

Processes mouse move events on behalf of the viewed widget.

Reimplemented from QScrollView.

### void QListView::contentsMousePressEvent ( QMouseEvent * e ) `[virtual protected]`

Processes mouse move events on behalf of the viewed widget.

Reimplemented from QScrollView.

### void QListView::contentsMouseReleaseEvent ( QMouseEvent * e ) `[virtual protected]`

Processes mouse move events on behalf of the viewed widget.

Reimplemented from QScrollView.

### void QListView::currentChanged ( QListViewItem * ) `[signal]`

This signal is emitted whenever the current item has changed (normally after the screen update). The current item is the item responsible for indicating keyboard focus.

The argument is the newly current item, or 0 if the change was to make no item current. This can happen e.g. if all items in the list view are deleted.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

See also setCurrentItem() and currentItem().

### QListViewItem * QListView::currentItem () const

Returns a pointer to the currently highlighted item, or 0 if there isn't any.

See also setCurrentItem().

### void QListView::doAutoScroll () `[protected slot]`

This slot handles auto-scrolling when the mouse button is pressed and the mouse is outside the widget.

### void QListView::doubleClicked ( QListViewItem * 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. item is the listview item onto which the user did the double click.

### void QListView::drawContentsOffset ( QPainter * p, int ox, int oy, int cx, int cy, int cw, int ch ) `[virtual protected]`

Calls QListViewItem::paintCell() and/or QListViewItem::paintBranches() for all list view items that require repainting. See the documentation for those functions for details.

Reimplemented from QScrollView.

### void QListView::enabledChange ( bool e ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### void QListView::ensureItemVisible ( const QListViewItem * i )

Ensures that i is made visible, scrolling the list view vertically as required and opens (expands)also all parent items if they hide their children.

See also itemRect() and QScrollView::ensureVisible().

### bool QListView::eventFilter ( QObject * o, QEvent * e ) `[virtual]`

Redirects events for the viewport to mousePressEvent(), keyPressEvent() and friends.

Reimplemented from QObject.

### void QListView::expanded ( QListViewItem * item ) `[signal]`

This signals is emitted when the item has been expanded. This means the children of the item are shown because the user double-clicked the item or clicked on the root decoration, or setOpen() with TRUE as argument has been called.

See also collapsed().

### QListViewItem * QListView::firstChild () const

Returns the first item in this QListView. You can use its firstChild() and nextSibling() functions to traverse the entire tree of items.

Returns 0 if there is no first item.

See also itemAt(), QListViewItem::itemBelow() and QListViewItem::itemAbove().

### void QListView::focusInEvent ( QFocusEvent * e ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### void QListView::focusOutEvent ( QFocusEvent * ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### QHeader * QListView::header () const

Returns a pointer to the QHeader object that manages this list view's columns. Please don't modify the header behind the list view's back.

Acceptable methods to call are:

- void QHeader::setClickEnabled( bool, int logIdx = -1 );
- void QHeader::setResizeEnabled( bool, int logIdx = -1 );
- void QHeader::setMovingEnabled( bool );

### void QListView::insertItem ( QListViewItem * i ) `[virtual]`

Inserts i into the list view as a top-level item. You do not need to call this unless you've called takeItem( i ) or QListViewItem::takeItem( i ) and need to reinsert i elsewhere.

See also QListViewItem::takeItem(), (important) and takeItem().

### void QListView::invertSelection () `[slot]`

Inverts the selection. Works only in Multi and Extended selection mode.

### bool QListView::isMultiSelection () const

Returns TRUE if this list view is in multi-selection mode and FALSE if it is in single-selection mode.

See also setMultiSelection().

### bool QListView::isOpen ( const QListViewItem * item ) const

Identical to item->isOpen(). Provided for completeness.

See also setOpen().

### bool QListView::isSelected ( const QListViewItem * i ) const

Returns i->isSelected().

Provided only because QListView provides setSelected() and trolls are neat creatures and like neat, orthogonal interfaces.

### QListViewItem * QListView::itemAt ( const QPoint & viewPos ) const

Returns a pointer to the QListViewItem at viewPos. Note that viewPos is in the coordinate system of viewport(), not in the listview's own, much larger, coordinate system.

itemAt() returns 0 if there is no such item.

Note, that you also get the pointer to the item if viewPos points onto the root decoration (see setRootIsDecorated()) of the item. To check if viewPos is on the root decoration of the item or not, you can do something like

      QListViewItem *i = itemAt( p );
      if ( i ) {
          if ( p.x() > header()->cellPos( header()->mapToActual( 0 ) ) +
                 treeStepSize() * ( i->depth() + ( rootIsDecorated() ? 1 : 0) ) + itemMargin() ||
                 p.x() < header()->cellPos( header()->mapToActual( 0 ) ) ) {
              ; // p is not not in root decoration
          else
              ; // p is in the root decoration
      }

This might be interesting if you use this method to find out where the user clicked and if you e.g. want to start a drag (which you do not want to do if the user clicked onto the root decoration of an item)

See also itemPos() and itemRect().

### int QListView::itemMargin () const

Returns the advisory item margin which list items may use.

See also QListViewItem::paintCell() and setItemMargin().

### int QListView::itemPos ( const QListViewItem * item )

Returns the y coordinate of item in the list view's coordinate system. This functions is normally much slower than itemAt(), but it works for all items, while itemAt() normally works only for items on the screen.

This is a thin wrapper around QListViewItem::itemPos().

See also itemAt() and itemRect().

### QRect QListView::itemRect ( const QListViewItem * i ) const

Returns the rectangle on the screen i occupies in viewport()'s coordinates, or an invalid rectangle if i is a null pointer or is not currently visible.

The rectangle returned does not include any children of the rectangle (ie. it uses QListViewItem::height() rather than QListViewItem::totalHeight()). If you want the rectangle including children, you can use something like this code:

        QRect r( listView->itemRect( item ) );
        r.setHeight( (QCOORD)(QMIN( item->totalHeight(),
                                    listView->viewport->height() - r.y() ) ) )

Note the way it avoids too-high rectangles. totalHeight() can be much larger than the window system's coordinate system allows.

itemRect() is comparatively slow. It's best to call it only for items that are probably on-screen.

### void QListView::keyPressEvent ( QKeyEvent * e ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### QSize QListView::minimumSizeHint () const `[virtual]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### void QListView::mouseButtonClicked ( int button, QListViewItem * item, const QPoint & pos, int c ) `[signal]`

This signal is emitted whenever the user clicks (mouse pressed + mouse released) into the listview. button is the mouse button which the user pressed, item is the pointer to the clicked listview item or NULL, if the user didn't click on an item, and c the listview column into which the user pressed (this argument is only valid, if item is not NULL!)

Note that you may not delete any QListViewItem objects in slots connected to this signal.

### void QListView::mouseButtonPressed ( int button, QListViewItem * item, const QPoint & pos, int c ) `[signal]`

This signal is emitted whenever the user pressed the mouse button onto the listview. button is the mouse button which the user pressed, item is the pointer to the pressed listview item or NULL, if the user didn't press on an item, and c the listview column into which the user pressed (this argument is only valid, if item is not NULL!)

Note that you may not delete any QListViewItem objects in slots connected to this signal.

### void QListView::onItem ( QListViewItem * i ) `[signal]`

This signal is emitted, when the user moves the mouse cursor onto an item. It´s only emitted once per item.

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

This signal is emitted, when the user moves the mouse cursor, which was on an item away from the item onto the viewport.

### void QListView::paintEmptyArea ( QPainter * p, const QRect & rect ) `[virtual protected]`

Paints rect so that it looks like empty background using painter p. rect is is widget coordinates, ready to be fed to p.

The default function fills rect with colorGroup().brush( QColorGroup::Base ).

### void QListView::pressed ( QListViewItem * item ) `[signal]`

This signal is emitted whenever the user presses the mouse button on a listview. item is the pointer to the listview item onto which the user pressed the mouse button or NULL, if the user didn't press the mouse on an item.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

### void QListView::pressed ( QListViewItem * item, const QPoint & pnt, int c ) `[signal]`

This signal is emitted whenever the user presses the mouse button on a listview. item is the pointer to the listview item onto which the user pressed the mouse button or NULL, if the user didn't press the mouse on an item. pnt is the position of the mouse cursor, and c the column into which the mouse cursor was when the user pressed the mouse button.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

### void QListView::removeColumn ( int index )

Removes the column at position index.

### void QListView::removeItem ( QListViewItem * i ) `[virtual]`

This function is obsolete. It is provided to keep old source working, and will probably be removed in a future version of Qt. We strongly advise against using it in new code.

This function has been renamed takeItem().

### void QListView::repaintItem ( const QListViewItem * item ) const

Repaints item on the screen, if item is currently visible. Takes care to avoid multiple repaints.

### void QListView::resizeEvent ( QResizeEvent * e ) `[virtual protected]`

Ensures that the header is correctly sized and positioned.

Reimplemented from QWidget.

### void QListView::returnPressed ( QListViewItem * ) `[signal]`

This signal is emitted when enter or return is pressed. The argument is currentItem().

### void QListView::rightButtonClicked ( QListViewItem *, const QPoint &, int ) `[signal]`

This signal is emitted when the right button is clicked (ie. when it's released). The arguments are the relevant QListViewItem (may be 0), the point in global coordinates and the relevant column (or -1 if the click was outside the list).

### void QListView::rightButtonPressed ( QListViewItem *, const QPoint &, int ) `[signal]`

This signal is emitted when the right button is pressed. Then arguments are the relevant QListViewItem (may be 0), the point in global coordinates and the relevant column (or -1 if the click was outside the list).

### bool QListView::rootIsDecorated () const

Returns TRUE if root items can be opened and closed by the user, FALSE if not.

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

If select is TRUE, all items get selected, else all get unselected. This works only in the selection modes Multi and Extended. In Single and NoSelection mode the selection of the current item is just set to select.

### QListViewItem * QListView::selectedItem () const

Returns a pointer to the selected item, if the list view is in single-selection mode and an item is selected.

If no items are selected or the list view is in multi-selection mode this function returns 0.

See also setSelected() and setMultiSelection().

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

This signal is emitted whenever the set of selected items has changed (normally before the screen update). It is available both in single-selection and multi-selection mode, but is most meaningful in multi-selection mode.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

See also setSelected() and QListViewItem::setSelected().

### void QListView::selectionChanged ( QListViewItem * ) `[signal]`

This signal is emitted whenever the selected item has changed in single-selection mode (normally after the screen update). The argument is the newly selected item.

There is another signal which is more useful in multi-selection mode.

Note that you may not delete any QListViewItem objects in slots connected to this signal.

See also setSelected(), QListViewItem::setSelected() and currentChanged().

### QListView::SelectionMode QListView::selectionMode() const

Returns the selection mode of the list view. The initial mode is `Single.`

See also setSelectionMode(), isMultiSelection() and setMultiSelection().

### void QListView::setAllColumnsShowFocus ( bool enable ) `[virtual]`

Sets this list view to assume that the items show focus and selection state using all of their columns if enable is TRUE, or that they show it just using column 0 if enable is FALSE.

The default is FALSE.

Setting this to TRUE if it isn't necessary can cause noticeable flicker.

See also allColumnsShowFocus().

Examples: dirview/main.cpp

### void QListView::setColumnAlignment ( int column, int align ) `[virtual]`

Configures the logical column column to have alignment align. The alignment is ultimately passed to QListViewItem::paintCell() for each item in the view.

See also Qt::AlignmentFlags.

### void QListView::setColumnText ( int column, const QIconSet & iconset, const QString & label ) `[virtual]`

Sets the heading text of column column to iconset and label. The leftmost colum is number 0.

### void QListView::setColumnText ( int column, const QString & label ) `[virtual]`

Sets the heading text of column column to label. The leftmost colum is number 0.

### void QListView::setColumnWidth ( int column, int w ) `[virtual]`

Sets the width of column column to w pixels. Note that if the column has a WidthMode other than Manual, this width setting may be subsequently overridden. The leftmost colum is number 0.

### void QListView::setColumnWidthMode ( int c, WidthMode mode )

Sets column c to behave according to mode. The default depends on whether the width argument to addColumn was positive or negative.

See also QListViewItem::width().

### void QListView::setContentsPos ( int x, int y ) `[virtual slot]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QScrollView.

### void QListView::setCurrentItem ( QListViewItem * i ) `[virtual]`

Sets i to be the current highlighted item and repaints appropriately. This highlighted item is used for keyboard navigation and focus indication; it doesn't mean anything else.

See also currentItem().

### void QListView::setFont ( const QFont & f ) `[virtual]`

Reimplemented for internal reasons; the API is not affected.

### void QListView::setItemMargin ( int m ) `[virtual]`

Sets the advisory item margin which list items may use to m.

The item margin defaults to one pixel and is the margin between the item's edges and the area where it draws its contents. QListViewItem::paintFocus() draws in the margin.

See also QListViewItem::paintCell().

### void QListView::setMultiSelection ( bool enable ) `[virtual]`

Sets the list view to multi-selection mode if enable is TRUE, and to single-selection mode if enable is FALSE.

If you enable multi-selection mode, it's possible to specify if this mode should be extended or not. Extended means, that the user can only select multiple items when pressing the Shift or Control button at the same time.

See also isMultiSelection().

### void QListView::setOpen ( QListViewItem * item, bool open ) `[virtual]`

Sets item to be open if open is TRUE and item is expandable, and to be closed if open is FALSE. Repaints accordingly.

Does nothing if item is not expandable.

See also QListViewItem::setOpen() and QListViewItem::setExpandable().

### void QListView::setPalette ( const QPalette & p ) `[virtual]`

Reimplemented for internal reasons; the API is not affected.

### void QListView::setRootIsDecorated ( bool enable ) `[virtual]`

Sets this list view to show open/close signs on root items if enable is TRUE, and to not show such signs if enable is FALSE.

Open/close signs is a little + or - in windows style, an arrow in Motif style.

### void QListView::setSelected ( QListViewItem * item, bool selected ) `[virtual]`

Sets item to be selected if selected is TRUE, and to be not selected if selected is FALSE.

If the list view is in single-selection mode and selected is TRUE, the currently selected item is unselected and item made current. Unlike QListViewItem::setSelected(), this function updates the list view as necessary and emits the selectionChanged() signals.

See also isSelected(), setMultiSelection(), isMultiSelection() and setCurrentItem().

### void QListView::setSelectionMode ( SelectionMode mode )

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

See also selectionMode().

### void QListView::setShowSortIndicator ( bool show )

If show is TRUE, draw an arrow in the header of the listview to indicate the sort order of the listview contents. The arrow will be drawn in the correct column and will point to the correct direction. Set show to FALSE to disable this feature.

See also QHeader::setSortIndicator().

### void QListView::setSorting ( int column, bool ascending = TRUE ) `[virtual]`

Set the list view to be sorted by column and to be sorted in ascending order if ascending is TRUE or descending order if it is FALSE.

If column is -1, sorting is disabled and the user cannot sort columns by clicking on the column headers.

### void QListView::setTreeStepSize ( int l ) `[virtual]`

Sets the the number of pixels a child is offset from its parent, in a tree view to l. The default is 20.

See also treeStepSize().

Examples: dirview/main.cpp

### void QListView::show () `[virtual]`

Reimplemented for internal reasons; the API is not affected.

Examples: dirview/main.cpp

Reimplemented from QWidget.

### void QListView::showEvent ( QShowEvent * ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### bool QListView::showSortIndicator () const

Returns TRUE, if the sort order and column are indicated in the header, else FALSE.

See also QListView::setSortIndicator().

### QSize QListView::sizeHint () const `[virtual]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### void QListView::sort ()

(Re)sorts the listview using the last sorting configuration (sort column and ascending/descending).

### void QListView::styleChange ( QStyle & old ) `[virtual protected]`

Reimplemented for internal reasons; the API is not affected.

Reimplemented from QWidget.

### void QListView::takeItem ( QListViewItem * i ) `[virtual]`

Removes i from the list view; i must be a top-level item. The warnings regarding QListViewItem::takeItem( i ) apply to this function too.

See also QListViewItem::takeItem(), (important) and insertItem().

### int QListView::treeStepSize () const

Returns the number of pixels a child is offset from its parent. This number has meaning only for tree views. The default is 20.

See also setTreeStepSize().

### void QListView::triggerUpdate () `[slot]`

Triggers a size, geometry and content update during the next iteration of the event loop. Cleverly makes sure that there'll be just one update, to avoid flicker.

### void QListView::updateContents () `[protected slot]`

Updates the sizes of the viewport, header, scrollbars and so on. Don't call this directly; call triggerUpdate() instead.

Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):

This file is part of the Qt toolkit, copyright © 1995-2005 Trolltech, all rights reserved.