Detailed Description
The QSmoothListWidget class provides an item-based list widget.
QSmoothListWidget 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. QSmoothListWidget uses an internal model to manage each QSmoothListWidgetItem in the list.
QSmoothListWidget is a drop-in replacement for QListWidget, but using a QSmoothList. This means that unlike a QListWidget a QSmoothListWidget does not handle editing, multiple selected items or drag and drop. The other noticable difference is that QSmoothListWidget::scrollToItem() takes a QSmoothList::ScrollHint as its second parameter, not a QAbstractItemView::ScrollHint.
For a more flexible list view widget, use the QSmoothList or the QListView class with a standard model.
There are two ways to add items to the list: they can be constructed with the smooth list widget as their parent widget, or they can be constructed with no parent widget and added to the list later. If a smooth list widget already exists when the items are constructed, the first method is easier to use:
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 smooth list widget will take ownership of the item.
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.
See also QSmoothListWidgetItem, QSmoothList, QListWidget, and Model/View Programming.
Property Documentation
count : const int
This property holds the number of items in the list.
Access functions:
currentRow : int
This property holds the row of the current item.
The row will also be selected.
Access functions:
- 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.
Access functions:
- bool isSortingEnabled () const
- void setSortingEnabled ( bool enable )
Member Function Documentation
QSmoothListWidget::QSmoothListWidget ( QWidget * parent = 0 )
Constructs an empty QSmoothListWidget with the given parent.
QSmoothListWidget::~QSmoothListWidget ()
Destroys the smooth list widget and all its items.
void QSmoothListWidget::addItem ( const QString & label )
Inserts an item with the text label at the end of the smooth list widget.
void QSmoothListWidget::addItem ( QSmoothListWidgetItem * item )
This is an overloaded member function, provided for convenience.
Inserts the item at the the end of the smooth list widget.
Warning: A QSmoothListWidgetItem can only be added to a QSmoothListWidget once. Adding the same QSmoothListWidgetItem multiple times to a QSmoothListWidget will result in undefined behavior.
See also insertItem().
void QSmoothListWidget::addItems ( const QStringList & labels )
Inserts items with the text labels at the end of the smooth list widget.
See also insertItems().
void QSmoothListWidget::clear () [slot]
Removes all items and selections in the view.
Note that all items will be permanently deleted.
Returns the current item.
See also setCurrentItem().
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 QSmoothListWidget::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.
Finds items with the text that matches the string text using the given flags.
Returns the QModelIndex assocated with the given item.
void QSmoothListWidget::insertItem ( int row, QSmoothListWidgetItem * item )
Inserts the item at the position in the list given by row.
See also addItem().
void QSmoothListWidget::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 QSmoothListWidget::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().
QSmoothListWidgetItem * QSmoothListWidget::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 QSmoothListWidget::itemActivated ( QSmoothListWidgetItem * 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).
Returns a pointer to the item at the coordinates p.
QSmoothListWidgetItem * QSmoothListWidget::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 QSmoothListWidget::itemClicked ( QSmoothListWidgetItem * 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 QSmoothListWidget::itemDoubleClicked ( QSmoothListWidgetItem * 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().
QSmoothListWidgetItem * QSmoothListWidget::itemFromIndex ( const QModelIndex & index ) const [protected]
Returns a pointer to the QSmoothListWidgetItem assocated with the given index.
void QSmoothListWidget::itemPressed ( QSmoothListWidgetItem * 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().
int QSmoothListWidget::row ( const QSmoothListWidgetItem * item ) const
Returns the row containing the given item.
See also item().
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.
Note that QSmoothList::ScrollHint is used instead of QAbstractItemView::ScrollHint
void QSmoothListWidget::setCurrentItem ( QSmoothListWidgetItem * item )
Sets the current item to item.
Depending on the current selection mode, the item may also be selected.
See also currentItem().
void QSmoothListWidget::sortItems ( Qt::SortOrder order = Qt::AscendingOrder )
Sorts all the items in the list widget according to the specified order.
Removes and returns the item from the given row in the smooth list widget; otherwise returns 0.
Items removed from a smooth list widget will not be managed by Qt, and will need to be deleted manually.
See also insertItem() and addItem().
QRect QSmoothListWidget::visualItemRect ( const QSmoothListWidgetItem * item ) const
Returns the rectangle on the viewport occupied by the item at item.