Warning, file /include/QtWidgets/qlistwidget.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004 #ifndef QLISTWIDGET_H
0005 #define QLISTWIDGET_H
0006
0007 #include <QtWidgets/qlistview.h>
0008 #include <QtWidgets/qtwidgetsglobal.h>
0009 #include <QtCore/qlist.h>
0010 #include <QtCore/qitemselectionmodel.h>
0011 #include <QtCore/qvariant.h>
0012
0013 QT_REQUIRE_CONFIG(listwidget);
0014
0015 QT_BEGIN_NAMESPACE
0016
0017 class QListWidget;
0018 class QListModel;
0019 class QWidgetItemData;
0020 class QListWidgetItemPrivate;
0021
0022 class Q_WIDGETS_EXPORT QListWidgetItem
0023 {
0024 friend class QListModel;
0025 friend class QListWidget;
0026 public:
0027 enum ItemType { Type = 0, UserType = 1000 };
0028 explicit QListWidgetItem(QListWidget *listview = nullptr, int type = Type);
0029 explicit QListWidgetItem(const QString &text, QListWidget *listview = nullptr, int type = Type);
0030 explicit QListWidgetItem(const QIcon &icon, const QString &text,
0031 QListWidget *listview = nullptr, int type = Type);
0032 QListWidgetItem(const QListWidgetItem &other);
0033 virtual ~QListWidgetItem();
0034
0035 virtual QListWidgetItem *clone() const;
0036
0037 inline QListWidget *listWidget() const { return view; }
0038
0039 void setSelected(bool select);
0040 bool isSelected() const;
0041
0042 inline void setHidden(bool hide);
0043 inline bool isHidden() const;
0044
0045 inline Qt::ItemFlags flags() const { return itemFlags; }
0046 void setFlags(Qt::ItemFlags flags);
0047
0048 inline QString text() const
0049 { return data(Qt::DisplayRole).toString(); }
0050 inline void setText(const QString &text);
0051
0052 inline QIcon icon() const
0053 { return qvariant_cast<QIcon>(data(Qt::DecorationRole)); }
0054 inline void setIcon(const QIcon &icon);
0055
0056 inline QString statusTip() const
0057 { return data(Qt::StatusTipRole).toString(); }
0058 inline void setStatusTip(const QString &statusTip);
0059
0060 #if QT_CONFIG(tooltip)
0061 inline QString toolTip() const
0062 { return data(Qt::ToolTipRole).toString(); }
0063 inline void setToolTip(const QString &toolTip);
0064 #endif
0065
0066 #if QT_CONFIG(whatsthis)
0067 inline QString whatsThis() const
0068 { return data(Qt::WhatsThisRole).toString(); }
0069 inline void setWhatsThis(const QString &whatsThis);
0070 #endif
0071
0072 inline QFont font() const
0073 { return qvariant_cast<QFont>(data(Qt::FontRole)); }
0074 inline void setFont(const QFont &font);
0075
0076 #if QT_VERSION < QT_VERSION_CHECK(7, 0, 0)
0077 inline int textAlignment() const
0078 { return data(Qt::TextAlignmentRole).toInt(); }
0079 #else
0080 inline Qt::Alignment textAlignment() const
0081 { return qvariant_cast<Qt::Alignment>(data(Qt::TextAlignmentRole)); }
0082 #endif
0083 #if QT_DEPRECATED_SINCE(6, 4)
0084 QT_DEPRECATED_VERSION_X_6_4("Use the overload taking Qt::Alignment")
0085 inline void setTextAlignment(int alignment)
0086 { setData(Qt::TextAlignmentRole, alignment); }
0087 inline void setTextAlignment(Qt::AlignmentFlag alignment)
0088 { setData(Qt::TextAlignmentRole, QVariant::fromValue(Qt::Alignment(alignment))); }
0089 #endif
0090 inline void setTextAlignment(Qt::Alignment alignment)
0091 { setData(Qt::TextAlignmentRole, QVariant::fromValue(alignment)); }
0092
0093 inline QBrush background() const
0094 { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
0095 inline void setBackground(const QBrush &brush)
0096 { setData(Qt::BackgroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); }
0097
0098 inline QBrush foreground() const
0099 { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
0100 inline void setForeground(const QBrush &brush)
0101 { setData(Qt::ForegroundRole, brush.style() != Qt::NoBrush ? QVariant(brush) : QVariant()); }
0102
0103 inline Qt::CheckState checkState() const
0104 { return qvariant_cast<Qt::CheckState>(data(Qt::CheckStateRole)); }
0105 inline void setCheckState(Qt::CheckState state)
0106 { setData(Qt::CheckStateRole, static_cast<int>(state)); }
0107
0108 inline QSize sizeHint() const
0109 { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); }
0110 inline void setSizeHint(const QSize &size)
0111 { setData(Qt::SizeHintRole, size.isValid() ? QVariant(size) : QVariant()); }
0112
0113 virtual QVariant data(int role) const;
0114 virtual void setData(int role, const QVariant &value);
0115
0116 virtual bool operator<(const QListWidgetItem &other) const;
0117
0118 #ifndef QT_NO_DATASTREAM
0119 virtual void read(QDataStream &in);
0120 virtual void write(QDataStream &out) const;
0121 #endif
0122 QListWidgetItem &operator=(const QListWidgetItem &other);
0123
0124 inline int type() const { return rtti; }
0125
0126 private:
0127 QListModel *listModel() const;
0128 int rtti;
0129 QListWidget *view;
0130 QListWidgetItemPrivate *d;
0131 Qt::ItemFlags itemFlags;
0132 };
0133
0134 inline void QListWidgetItem::setText(const QString &atext)
0135 { setData(Qt::DisplayRole, atext); }
0136
0137 inline void QListWidgetItem::setIcon(const QIcon &aicon)
0138 { setData(Qt::DecorationRole, aicon); }
0139
0140 inline void QListWidgetItem::setStatusTip(const QString &astatusTip)
0141 { setData(Qt::StatusTipRole, astatusTip); }
0142
0143 #if QT_CONFIG(tooltip)
0144 inline void QListWidgetItem::setToolTip(const QString &atoolTip)
0145 { setData(Qt::ToolTipRole, atoolTip); }
0146 #endif
0147
0148 #if QT_CONFIG(whatsthis)
0149 inline void QListWidgetItem::setWhatsThis(const QString &awhatsThis)
0150 { setData(Qt::WhatsThisRole, awhatsThis); }
0151 #endif
0152
0153 inline void QListWidgetItem::setFont(const QFont &afont)
0154 { setData(Qt::FontRole, afont); }
0155
0156 #ifndef QT_NO_DATASTREAM
0157 Q_WIDGETS_EXPORT QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item);
0158 Q_WIDGETS_EXPORT QDataStream &operator>>(QDataStream &in, QListWidgetItem &item);
0159 #endif
0160
0161 class QListWidgetPrivate;
0162
0163 class Q_WIDGETS_EXPORT QListWidget : public QListView
0164 {
0165 Q_OBJECT
0166 Q_PROPERTY(int count READ count)
0167 Q_PROPERTY(int currentRow READ currentRow WRITE setCurrentRow NOTIFY currentRowChanged
0168 USER true)
0169 Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
0170
0171 friend class QListWidgetItem;
0172 friend class QListModel;
0173 public:
0174 explicit QListWidget(QWidget *parent = nullptr);
0175 ~QListWidget();
0176
0177 void setSelectionModel(QItemSelectionModel *selectionModel) override;
0178
0179 QListWidgetItem *item(int row) const;
0180 int row(const QListWidgetItem *item) const;
0181 void insertItem(int row, QListWidgetItem *item);
0182 void insertItem(int row, const QString &label);
0183 void insertItems(int row, const QStringList &labels);
0184 inline void addItem(const QString &label) { insertItem(count(), label); }
0185 inline void addItem(QListWidgetItem *item);
0186 inline void addItems(const QStringList &labels) { insertItems(count(), labels); }
0187 QListWidgetItem *takeItem(int row);
0188 int count() const;
0189
0190 QListWidgetItem *currentItem() const;
0191 void setCurrentItem(QListWidgetItem *item);
0192 void setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command);
0193
0194 int currentRow() const;
0195 void setCurrentRow(int row);
0196 void setCurrentRow(int row, QItemSelectionModel::SelectionFlags command);
0197
0198 QListWidgetItem *itemAt(const QPoint &p) const;
0199 inline QListWidgetItem *itemAt(int x, int y) const;
0200 QRect visualItemRect(const QListWidgetItem *item) const;
0201
0202 void sortItems(Qt::SortOrder order = Qt::AscendingOrder);
0203 void setSortingEnabled(bool enable);
0204 bool isSortingEnabled() const;
0205
0206 void editItem(QListWidgetItem *item);
0207 void openPersistentEditor(QListWidgetItem *item);
0208 void closePersistentEditor(QListWidgetItem *item);
0209 using QAbstractItemView::isPersistentEditorOpen;
0210 bool isPersistentEditorOpen(QListWidgetItem *item) const;
0211
0212 QWidget *itemWidget(QListWidgetItem *item) const;
0213 void setItemWidget(QListWidgetItem *item, QWidget *widget);
0214 inline void removeItemWidget(QListWidgetItem *item);
0215
0216 QList<QListWidgetItem*> selectedItems() const;
0217 QList<QListWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
0218
0219 QList<QListWidgetItem*> items(const QMimeData *data) const;
0220
0221 QModelIndex indexFromItem(const QListWidgetItem *item) const;
0222 QListWidgetItem *itemFromIndex(const QModelIndex &index) const;
0223
0224 protected:
0225 #if QT_CONFIG(draganddrop)
0226 void dropEvent(QDropEvent *event) override;
0227 #endif
0228 public Q_SLOTS:
0229 void scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible);
0230 void clear();
0231
0232 Q_SIGNALS:
0233 void itemPressed(QListWidgetItem *item);
0234 void itemClicked(QListWidgetItem *item);
0235 void itemDoubleClicked(QListWidgetItem *item);
0236 void itemActivated(QListWidgetItem *item);
0237 void itemEntered(QListWidgetItem *item);
0238 void itemChanged(QListWidgetItem *item);
0239
0240 void currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
0241 void currentTextChanged(const QString ¤tText);
0242 void currentRowChanged(int currentRow);
0243
0244 void itemSelectionChanged();
0245
0246 protected:
0247 bool event(QEvent *e) override;
0248 virtual QStringList mimeTypes() const;
0249 virtual QMimeData *mimeData(const QList<QListWidgetItem *> &items) const;
0250 #if QT_CONFIG(draganddrop)
0251 virtual bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action);
0252 virtual Qt::DropActions supportedDropActions() const;
0253 #endif
0254
0255 private:
0256 void setModel(QAbstractItemModel *model) override;
0257 Qt::SortOrder sortOrder() const;
0258
0259 Q_DECLARE_PRIVATE(QListWidget)
0260 Q_DISABLE_COPY(QListWidget)
0261 };
0262
0263 inline void QListWidget::removeItemWidget(QListWidgetItem *aItem)
0264 { setItemWidget(aItem, nullptr); }
0265
0266 inline void QListWidget::addItem(QListWidgetItem *aitem)
0267 { insertItem(count(), aitem); }
0268
0269 inline QListWidgetItem *QListWidget::itemAt(int ax, int ay) const
0270 { return itemAt(QPoint(ax, ay)); }
0271
0272 inline void QListWidgetItem::setHidden(bool ahide)
0273 { if (view) view->setRowHidden(view->row(this), ahide); }
0274
0275 inline bool QListWidgetItem::isHidden() const
0276 { return (view ? view->isRowHidden(view->row(this)) : false); }
0277
0278 QT_END_NAMESPACE
0279
0280 #endif