⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qlistwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
{    Q_D(const QListWidget);    return d->model()->rowCount();}/*!  Returns the current item.*/QListWidgetItem *QListWidget::currentItem() const{    Q_D(const QListWidget);    return d->model()->at(currentIndex().row());}/*!  Sets the current item to \a item.  Depending on the current selection mode, the item may also be selected.*/void QListWidget::setCurrentItem(QListWidgetItem *item){    setCurrentRow(row(item));}/*!  \property QListWidget::currentRow  \brief the row of the current item.  Depending on the current selection mode, the row may also be selected.*/int QListWidget::currentRow() const{    return currentIndex().row();}void QListWidget::setCurrentRow(int row){    Q_D(QListWidget);    QModelIndex index = d->model()->index(row);    if (d->selectionMode == SingleSelection)        selectionModel()->setCurrentIndex(index, QItemSelectionModel::ClearAndSelect);    else if (d->selectionMode == NoSelection)        selectionModel()->setCurrentIndex(index, QItemSelectionModel::NoUpdate);    else        selectionModel()->setCurrentIndex(index, QItemSelectionModel::SelectCurrent);}/*!    Returns a pointer to the item at the coordinates \a p.*/QListWidgetItem *QListWidget::itemAt(const QPoint &p) const{    Q_D(const QListWidget);    return d->model()->at(indexAt(p).row());}/*!    \fn QListWidgetItem *QListWidget::itemAt(int x, int y) const    \overload    Returns a pointer to the item at the coordinates (\a x, \a y).*//*!  Returns the rectangle on the viewport occupied by the item at \a item.*/QRect QListWidget::visualItemRect(const QListWidgetItem *item) const{    Q_D(const QListWidget);    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));    return visualRect(index);}/*!  Sorts all the items in the list widget according to the specified \a order.*/void QListWidget::sortItems(Qt::SortOrder order){    Q_D(QListWidget);    d->sortOrder = order;    d->model()->sort(0, order);}/*!    \since Qt 4.2    \property QListWidget::sortingEnabled    \brief 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.*/void QListWidget::setSortingEnabled(bool enable){    Q_D(QListWidget);    d->sortingEnabled = enable;}bool QListWidget::isSortingEnabled() const{    Q_D(const QListWidget);    return d->sortingEnabled;}/*!  \internal*/Qt::SortOrder QListWidget::sortOrder() const{    Q_D(const QListWidget);    return d->sortOrder;}/*!  Starts editing the \a item if it is editable.*/void QListWidget::editItem(QListWidgetItem *item){    Q_D(QListWidget);    edit(d->model()->index(item));}/*!  Opens an editor for the given \a item. The editor remains open after editing.  \sa closePersistentEditor()*/void QListWidget::openPersistentEditor(QListWidgetItem *item){    Q_D(QListWidget);    QModelIndex index = d->model()->index(item);    QAbstractItemView::openPersistentEditor(index);}/*!  Closes the persistent editor for the given \a item.  \sa openPersistentEditor()*/void QListWidget::closePersistentEditor(QListWidgetItem *item){    Q_D(QListWidget);    QModelIndex index = d->model()->index(item);    QAbstractItemView::closePersistentEditor(index);}/*!    \since 4.1    Returns the widget displayed in the given \a item.*/QWidget *QListWidget::itemWidget(QListWidgetItem *item) const{    Q_D(const QListWidget);    QModelIndex index = d->model()->index(item);    return QAbstractItemView::indexWidget(index);}/*!    \since 4.1    Sets the \a widget to be displayed in the give \a 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.    \sa {Delegate Classes}*/void QListWidget::setItemWidget(QListWidgetItem *item, QWidget *widget){    Q_D(QListWidget);    QModelIndex index = d->model()->index(item);    QAbstractItemView::setIndexWidget(index, widget);}/*!  Returns true if \a item is selected; otherwise returns false.  \obsolete  This function is deprecated. Use \l{QListWidgetItem::isSelected()} instead.*/bool QListWidget::isItemSelected(const QListWidgetItem *item) const{    Q_D(const QListWidget);    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));    return selectionModel()->isSelected(index);}/*!  Selects or deselects the given \a item depending on whether \a select is  true of false.  \obsolete  This function is deprecated. Use \l{QListWidgetItem::setSelected()} instead.*/void QListWidget::setItemSelected(const QListWidgetItem *item, bool select){    Q_D(QListWidget);    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));        if (d->selectionMode == SingleSelection) {        selectionModel()->select(index, select                                  ? QItemSelectionModel::ClearAndSelect                                 : QItemSelectionModel::Deselect);    } else if (d->selectionMode != NoSelection) {        selectionModel()->select(index, select                                 ? QItemSelectionModel::Select                                 : QItemSelectionModel::Deselect);    }}/*!  Returns a list of all selected items in the list widget.*/QList<QListWidgetItem*> QListWidget::selectedItems() const{    Q_D(const QListWidget);    QModelIndexList indexes = selectionModel()->selectedIndexes();    QList<QListWidgetItem*> items;    for (int i = 0; i < indexes.count(); ++i)        items.append(d->model()->at(indexes.at(i).row()));    return items;}/*!  Finds items with the text that matches the string \a text using the given \a flags.*/QList<QListWidgetItem*> QListWidget::findItems(const QString &text, Qt::MatchFlags flags) const{    Q_D(const QListWidget);    QModelIndexList indexes = d->model()->match(model()->index(0, 0, QModelIndex()),                                                Qt::DisplayRole, text, -1, flags);    QList<QListWidgetItem*> items;    for (int i = 0; i < indexes.size(); ++i)        items.append(d->model()->at(indexes.at(i).row()));    return items;}/*!  Returns true if the \a item is explicitly hidden; otherwise returns false.  \obsolete  This function is deprecated. Use \l{QListWidgetItem::isHidden()} instead.*/bool QListWidget::isItemHidden(const QListWidgetItem *item) const{    return isRowHidden(row(item));}/*!  If \a hide is true, the \a item will be hidden; otherwise it will be shown.  \obsolete  This function is deprecated. Use \l{QListWidgetItem::setHidden()} instead.*/void QListWidget::setItemHidden(const QListWidgetItem *item, bool hide){    setRowHidden(row(item), hide);}/*!    Scrolls the view if necessary to ensure that the \a item is    visible. The \a hint parameter specifies more precisely where the    \a item should be located after the operation.*/void QListWidget::scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint){    Q_D(QListWidget);    QModelIndex index = d->model()->index(const_cast<QListWidgetItem*>(item));    QListView::scrollTo(index, hint);}/*!  Removes all items and selections in the view.*/void QListWidget::clear(){    Q_D(QListWidget);    selectionModel()->clear();    d->model()->clear();}/*!    Returns a list of MIME types that can be used to describe a list of    listwidget items.    \sa mimeData()*/QStringList QListWidget::mimeTypes() const{    return d_func()->model()->QAbstractListModel::mimeTypes();}/*!    Returns an object that contains a serialized description of the specified    \a 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.*/QMimeData *QListWidget::mimeData(const QList<QListWidgetItem*>) const{    return d_func()->model()->internalMimeData();}#ifndef QT_NO_DRAGANDDROP/*!    Handles the \a data supplied by a drag and drop operation that ended with    the given \a action in the given \a index.    Returns true if the data and action can be handled by the model;    otherwise returns false.    \sa supportedDropActions()*/bool QListWidget::dropMimeData(int index, const QMimeData *data, Qt::DropAction action){    QModelIndex idx;    int row = index;    int column = 0;    if (dropIndicatorPosition() == QAbstractItemView::OnItem) {        // QAbstractListModel::dropMimeData will overwrite on the index if row == -1 and column == -1        idx = model()->index(row, column);        row = -1;        column = -1;    }    return d_func()->model()->QAbstractListModel::dropMimeData(data, action , row, column, idx);}/*! \reimp */void QListWidget::dropEvent(QDropEvent *event) {    Q_D(QListWidget);    if (event->source() == this && d->movement != Static) {        QListView::dropEvent(event);        return;    }    if (event->source() == this && (event->proposedAction() == Qt::MoveAction ||                                    dragDropMode() == QAbstractItemView::InternalMove)) {        QModelIndex topIndex;        int col = -1;        int row = -1;        if (d->dropOn(event, &row, &col, &topIndex)) {            QList<QModelIndex> selIndexes = selectedIndexes();            QList<QPersistentModelIndex> persIndexes;            for(int i = 0; i < selIndexes.count(); i++)                persIndexes.append(selIndexes.at(i));            if (persIndexes.contains(topIndex))                return;            QPersistentModelIndex dropRow = model()->index(row, col, topIndex);            QList<QListWidgetItem *> taken;            for (int i = 0; i < persIndexes.count(); ++i)                taken.append(takeItem(persIndexes.at(i).row()));            // insert them back in at their new positions            for (int i = 0; i < persIndexes.count(); ++i) {                // Either at a specific point or appended                if (row == -1) {                    insertItem(count(), taken.takeFirst());                } else {                    int r = dropRow.row() >= 0 ? dropRow.row() : row;                    insertItem(qMin(r, count()), taken.takeFirst());                }            }            event->accept();            // Don't want QAbstractItemView to delete it because it was "moved" we already did it            event->setDropAction(Qt::CopyAction);        }    }    QListView::dropEvent(event);}/*!  Returns the drop actions supported by this view.  \sa Qt::DropActions*/Qt::DropActions QListWidget::supportedDropActions() const{    Q_D(const QListWidget);    return d->model()->QAbstractListModel::supportedDropActions() | Qt::MoveAction;}#endif // QT_NO_DRAGANDDROP/*!  Returns a list of pointers to the items contained in the \a data object.  If the object was not created by a QListWidget in the same process, the list  is empty.*/QList<QListWidgetItem*> QListWidget::items(const QMimeData *data) const{    const QListWidgetMimeData *lwd = qobject_cast<const QListWidgetMimeData*>(data);    if (lwd)        return lwd->items;    return QList<QListWidgetItem*>();}/*!  Returns the QModelIndex assocated with the given \a item.*/QModelIndex QListWidget::indexFromItem(QListWidgetItem *item) const{    Q_D(const QListWidget);    return d->model()->index(item);}/*!  Returns a pointer to the QListWidgetItem assocated with the given \a index.*/QListWidgetItem *QListWidget::itemFromIndex(const QModelIndex &index) const{    Q_D(const QListWidget);    if (d->isIndexValid(index))        return d->model()->at(index.row());    return 0;}/*!  \internal*/void QListWidget::setModel(QAbstractItemModel * /*model*/){    qFatal("QListWidget::setModel() - Changing the model of the QListWidget is not allowed.");}/*!    \reimp*/bool QListWidget::event(QEvent *e){    return QListView::event(e);}#include "moc_qlistwidget.cpp"#endif // QT_NO_LISTWIDGET

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -