Qt:Документация 4.3.2/qlistwidget

Материал из Wiki.crossplatform.ru

Перейти к: навигация, поиск
40px Внимание: Актуальная версия перевода документации находится здесь

__NOTOC__

Image:qt-logo.png

Главная · Все классы · Основные классы · Классы по группам · Модули · Функции

Image:trolltech-logo.png

Содержание

[править] QListWidget Class Reference
[модуль QtGui ]

The QListWidget class provides an item-based list widget. More...

 #include <QListWidget>

Inherits QListView.

[править] Свойства

  • 13 свойства унаследованных от QListView
  • 14 свойства унаследованных от QAbstractItemView
  • 2 свойства унаследованных от QAbstractScrollArea
  • 6 свойства унаследованных от QFrame
  • 56 свойства унаследованных от QWidget
  • 1 свойство унаследованное от QObject

[править] Открытые функции

  • 29 открытых функций унаследованных от QListView
  • 52 открытых функций унаследованных от QAbstractItemView
  • 15 открытых функций унаследованных от QAbstractScrollArea
  • 13 открытых функций унаследованных от QFrame
  • 201 открытых функций унаследованных от QWidget
  • 29 открытых функций унаследованных от QObject
  • 12 открытых функций унаследованных от QPaintDevice

[править] Открытые слоты

  • void clear ()
  • void scrollToItem ( const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible )
  • 9 открытых слотов унаследованных от QAbstractItemView
  • 19 открытых слотов унаследованных от QWidget
  • 1 открытый слот унаследованный от QObject

[править] Сигналы

  • 1 сигнал унаследованный от QListView
  • 6 сигнала унаследованных от QAbstractItemView
  • 1 сигнал унаследованный от QWidget
  • 1 сигнал унаследованный от QObject

[править] Защищенные функции

  • virtual bool dropMimeData ( int index, const QMimeData * data, Qt::DropAction action )
  • QModelIndex indexFromItem ( QListWidgetItem * item ) const
  • QListWidgetItem * itemFromIndex ( const QModelIndex & index ) const
  • QList<QListWidgetItem *> items ( const QMimeData * data ) const
  • virtual QMimeData * mimeData ( const QList<QListWidgetItem *> items ) const
  • virtual QStringList mimeTypes () const
  • virtual Qt::DropActions supportedDropActions () const
  • 2 защищенных функций унаследованных от QListView
  • 33 защищенных функций унаследованных от QAbstractItemView
  • 16 защищенных функций унаследованных от QAbstractScrollArea
  • 38 защищенных функций унаследованных от QWidget
  • 7 защищенных функций унаследованных от QObject
  • 1 защищенная функция унаследованна от QPaintDevice

[править] Дополнительные унаследованные члены

  • 4 статических открытых члена унаследованных от QWidget
  • 5 статических открытых члена унаследованных от QObject
  • 8 защищенных слотов унаследованных от QAbstractItemView
  • 1 защищенный слот унаследованный от QAbstractScrollArea
  • 1 защищенный слот унаследованный от QWidget

[править] Подробное описание

The QListWidget class provides an item-based list widget.

QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for adding and removing items. QListWidget uses an internal model to manage each QListWidgetItem in the list.

For a more flexible list view widget, use the QListView class with a standard model.

List widgets are constructed in the same way as other widgets:

     QListWidget *listWidget = new QListWidget(this);

The selectionMode() of a list widget determines how many of the items in the list can be selected at the same time, and whether complex selections of items can be created. This can be set with the setSelectionMode() function.

There are two ways to add items to the list: they can be constructed with the list widget as their parent widget, or they can be constructed with no parent widget and added to the list later. If a list widget already exists when the items are constructed, the first method is easier to use:

     new QListWidgetItem(tr("Oak"), listWidget);
     new QListWidgetItem(tr("Fir"), listWidget);
     new QListWidgetItem(tr("Pine"), listWidget);

If you need to insert a new item into the list at a particular position, it is more required to construct the item without a parent widget and use the insertItem() function to place it within the list. The list widget will take ownership of the item.

     QListWidgetItem *newItem = new QListWidgetItem;
     newItem->setText(itemText);
     listWidget->insertItem(row, newItem);

For multiple items, insertItems() can be used instead. The number of items in the list is found with the count() function. To remove items from the list, use takeItem().

The current item in the list can be found with currentItem(), and changed with setCurrentItem(). The user can also change the current item by navigating with the keyboard or clicking on a different item. When the current item changes, the currentItemChanged() signal is emitted with the new current item and the item that was previously current.


center center Файл:Plastique-listview.png
A Windows XP style list widget. A Macintosh style list widget. A Plastique style list widget.

See also QListWidgetItem, QListView, QTreeView, Model/View Programming, and Config Dialog Example.


[править] Описание свойств

[править]
count : const int

This property holds the number of items in the list including any hidden items.

Функции доступа:

  • int count () const

[править]
currentRow : int

This property holds the row of the current item.

Depending on the current selection mode, the row may also be selected.

Функции доступа:

  • int currentRow () const
  • void setCurrentRow ( int row )

[править]
sortingEnabled : bool

This property holds whether sorting is enabled.

If this property is true, sorting is enabled for the list; if the property is false, sorting is not enabled. The default value is false.

This property was introduced in Qt Qt 4.2.

Функции доступа:

  • bool isSortingEnabled () const
  • void setSortingEnabled ( bool enable )

[править] Описание функций-членов

[править]
QListWidget::QListWidget ( QWidget * parent = 0 )

Constructs an empty QListWidget with the given parent.

[править]
QListWidget::~QListWidget ()

Destroys the list widget and all its items.

[править]
void QListWidget::addItem ( const QString & label )

Inserts an item with the text label at the end of the list widget.

[править]
void QListWidget::addItem ( QListWidgetItem * item )

This is an overloaded member function, provided for convenience.

Inserts the item at the the end of the list widget.

Warning: A QListWidgetItem can only be added to a QListWidget once. Adding the same QListWidgetItem multiple times to a QListWidget will result in undefined behavior.

See also insertItem().

[править]
void QListWidget::addItems ( const QStringList & labels )

Inserts items with the text labels at the end of the list widget.

See also insertItems().

[править]
void QListWidget::clear () [slot]

Removes all items and selections in the view.

[править]
void QListWidget::closePersistentEditor ( QListWidgetItem * item )

Closes the persistent editor for the given item.

See also openPersistentEditor().

[править]
QListWidgetItem * QListWidget::currentItem () const

Returns the current item.

See also setCurrentItem().

[править]
void QListWidget::currentItemChanged ( QListWidgetItem * current, QListWidgetItem * previous ) [signal]

This signal is emitted whenever the current item changes. The previous item is the item that previously had the focus, current is the new current item.

[править]
void QListWidget::currentRowChanged ( int currentRow ) [signal]

This signal is emitted whenever the current item changes. The currentRow is the row of the current item. If there is no current item, the currentRow is -1.

[править]
void QListWidget::currentTextChanged ( const QString & currentText ) [signal]

This signal is emitted whenever the current item changes. The currentText is the text data in the current item. If there is no current item, the currentText is invalid.

[править]
bool QListWidget::dropMimeData ( int index, const QMimeData * data, Qt::DropAction action ) [virtual protected]

Handles the data supplied by a drag and drop operation that ended with the given action in the given index. Returns true if the data and action can be handled by the model; otherwise returns false.

See also supportedDropActions().

[править]
void QListWidget::editItem ( QListWidgetItem * item )

Starts editing the item if it is editable.

[править]
QList< QListWidgetItem *> QListWidget::findItems ( const QString & text, Qt::MatchFlags flags ) const

Finds items with the text that matches the string text using the given flags.

[править]
QModelIndex QListWidget::indexFromItem ( QListWidgetItem * item ) const [protected]

Returns the QModelIndex assocated with the given item.

[править]
void QListWidget::insertItem ( int row, QListWidgetItem * item )

Inserts the item at the position in the list given by row.

See also addItem().

[править]
void QListWidget::insertItem ( int row, const QString & label )

This is an overloaded member function, provided for convenience.

Inserts an item with the text label in the list widget at the position given by row.

See also addItem().

[править]
void QListWidget::insertItems ( int row, const QStringList & labels )

Inserts items from the list of labels into the list, starting at the given row.

See also insertItem() and addItem().

[править]
QListWidgetItem * QListWidget::item ( int row ) const

Returns the item that occupies the given row in the list if one has been set; otherwise returns 0.

See also row().

[править]
void QListWidget::itemActivated ( QListWidgetItem * item ) [signal]

This signal is emitted when the item is activated. The item is activated when the user clicks or double clicks on it, depending on the system configuration. It is also activated when the user presses the activation key (on Windows and X11 this is the Return key, on Mac OS X it is Ctrl+0).

[править]
QListWidgetItem * QListWidget::itemAt ( const QPoint & p ) const

Returns a pointer to the item at the coordinates p.

[править]
QListWidgetItem * QListWidget::itemAt ( int x, int y ) const

This is an overloaded member function, provided for convenience.

Returns a pointer to the item at the coordinates (x, y).

[править]
void QListWidget::itemChanged ( QListWidgetItem * item ) [signal]

This signal is emitted whenever the data of item has changed.

[править]
void QListWidget::itemClicked ( QListWidgetItem * item ) [signal]

This signal is emitted with the specified item when a mouse button is clicked on an item in the widget.

See also itemPressed() and itemDoubleClicked().

[править]
void QListWidget::itemDoubleClicked ( QListWidgetItem * item ) [signal]

This signal is emitted with the specified item when a mouse button is double clicked on an item in the widget.

See also itemClicked() and itemPressed().

[править]
void QListWidget::itemEntered ( QListWidgetItem * item ) [signal]

This signal is emitted when the mouse cursor enters an item. The item is the item entered. This signal is only emitted when mouseTracking is turned on, or when a mouse button is pressed while moving into an item.

[править]
QListWidgetItem * QListWidget::itemFromIndex ( const QModelIndex & index ) const [protected]

Returns a pointer to the QListWidgetItem assocated with the given index.

[править]
void QListWidget::itemPressed ( QListWidgetItem * item ) [signal]

This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.

See also itemClicked() and itemDoubleClicked().

[править]
void QListWidget::itemSelectionChanged () [signal]

This signal is emitted whenever the selection changes.

See also selectedItems(), isItemSelected(), and currentItemChanged().

[править]
QWidget * QListWidget::itemWidget ( QListWidgetItem * item ) const

Returns the widget displayed in the given item.

This function was introduced in Qt 4.1.

See also setItemWidget().

[править]
QList< QListWidgetItem *> QListWidget::items ( const QMimeData * data ) const [protected]

Returns a list of pointers to the items contained in the data object. If the object was not created by a QListWidget in the same process, the list is empty.

[править]
QMimeData * QListWidget::mimeData ( const QList< QListWidgetItem *> items ) const [virtual protected]

Returns an object that contains a serialized description of the specified items. The format used to describe the items is obtained from the mimeTypes() function.

If the list of items is empty, 0 is returned rather than a serialized empty list.

[править]
QStringList QListWidget::mimeTypes () const [virtual protected]

Returns a list of MIME types that can be used to describe a list of listwidget items.

See also mimeData().

[править]
void QListWidget::openPersistentEditor ( QListWidgetItem * item )

Opens an editor for the given item. The editor remains open after editing.

See also closePersistentEditor().

[править]
void QListWidget::removeItemWidget ( QListWidgetItem * item )

Removes the widget set on the given item.

This function was introduced in Qt 4.3.

[править]
int QListWidget::row ( const QListWidgetItem * item ) const

Returns the row containing the given item.

See also item().

[править]
void QListWidget::scrollToItem ( const QListWidgetItem * item, QAbstractItemView::ScrollHint hint = EnsureVisible ) [slot]

Scrolls the view if necessary to ensure that the item is visible. The hint parameter specifies more precisely where the item should be located after the operation.

[править]
QList< QListWidgetItem *> QListWidget::selectedItems () const

Returns a list of all selected items in the list widget.

[править]
void QListWidget::setCurrentItem ( QListWidgetItem * item )

Sets the current item to item.

Depending on the current selection mode, the item may also be selected.

See also currentItem().

[править]
void QListWidget::setItemWidget ( QListWidgetItem * item, QWidget * widget )

Sets the widget to be displayed in the give item.

This function should only be used to display static content in the place of a list widget item. If you want to display custom dynamic content or implement a custom editor widget, use QListView and subclass QItemDelegate instead.

This function was introduced in Qt 4.1.

See also itemWidget() and Delegate Classes.

[править]
void QListWidget::sortItems ( Qt::SortOrder order = Qt::AscendingOrder )

Sorts all the items in the list widget according to the specified order.

[править]
Qt::DropActions QListWidget::supportedDropActions () const [virtual protected]

Returns the drop actions supported by this view.

See also Qt::DropActions.

[править]
QListWidgetItem * QListWidget::takeItem ( int row )

Removes and returns the item from the given row in the list widget; otherwise returns 0.

Items removed from a list widget will not be managed by Qt, and will need to be deleted manually.

See also insertItem() and addItem().

[править]
QRect QListWidget::visualItemRect ( const QListWidgetItem * item ) const

Returns the rectangle on the viewport occupied by the item at item.


Copyright © 2007 Trolltech Trademarks
Qt 4.3.2