- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files
- Directories
- Examples

- File List
- File Members

# qlistwidget.h

Go to the documentation of this file.

    00001 /****************************************************************************
    00002 **
    00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
    00004 ** All rights reserved.
    00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
    00006 **
    00007 ** This file is part of the QtGui module of the Qt Toolkit.
    00008 **
    00009 ** $QT_BEGIN_LICENSE:LGPL$
    00010 ** Commercial Usage
    00011 ** Licensees holding valid Qt Commercial licenses may use this file in
    00012 ** accordance with the Qt Commercial License Agreement provided with the
    00013 ** Software or, alternatively, in accordance with the terms contained in
    00014 ** a written agreement between you and Nokia.
    00015 **
    00016 ** GNU Lesser General Public License Usage
    00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
    00018 ** General Public License version 2.1 as published by the Free Software
    00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
    00020 ** packaging of this file.  Please review the following information to
    00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
    00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    00023 **
    00024 ** In addition, as a special exception, Nokia gives you certain additional
    00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
    00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
    00027 **
    00028 ** GNU General Public License Usage
    00029 ** Alternatively, this file may be used under the terms of the GNU
    00030 ** General Public License version 3.0 as published by the Free Software
    00031 ** Foundation and appearing in the file LICENSE.GPL included in the
    00032 ** packaging of this file.  Please review the following information to
    00033 ** ensure the GNU General Public License version 3.0 requirements will be
    00034 ** met: http://www.gnu.org/copyleft/gpl.html.
    00035 **
    00036 ** If you have questions regarding the use of this file, please contact
    00037 ** Nokia at qt-info@nokia.com.
    00038 ** $QT_END_LICENSE$
    00039 **
    00040 ****************************************************************************/
    00041
    00042 #ifndef QLISTWIDGET_H
    00043 #define QLISTWIDGET_H
    00044
    00045 #include <QtGui/qlistview.h>
    00046 #include <QtCore/qvariant.h>
    00047 #include <QtCore/qvector.h>
    00048 #include <QtGui/qitemselectionmodel.h>
    00049
    00050 QT_BEGIN_HEADER
    00051
    00052 QT_BEGIN_NAMESPACE
    00053
    00054 QT_MODULE(Gui)
    00055
    00056 #ifndef QT_NO_LISTWIDGET
    00057
    00058 class QListWidget;
    00059 class QListModel;
    00060 class QWidgetItemData;
    00061 class QListWidgetItemPrivate;
    00062
    00063 class Q_GUI_EXPORT QListWidgetItem
    00064 {
    00065     friend class QListModel;
    00066     friend class QListWidget;
    00067 public:
    00068     enum ItemType { Type = 0, UserType = 1000 };
    00069     explicit QListWidgetItem(QListWidget *view = 0, int type = Type);
    00070     explicit QListWidgetItem(const QString &text, QListWidget *view = 0, int type = Type);
    00071     explicit QListWidgetItem(const QIcon &icon, const QString &text,
    00072                              QListWidget *view = 0, int type = Type);
    00073     QListWidgetItem(const QListWidgetItem &other);
    00074     virtual ~QListWidgetItem();
    00075
    00076     virtual QListWidgetItem *clone() const;
    00077
    00078     inline QListWidget *listWidget() const { return view; }
    00079
    00080     inline void setSelected(bool select);
    00081     inline bool isSelected() const;
    00082
    00083     inline void setHidden(bool hide);
    00084     inline bool isHidden() const;
    00085
    00086     inline Qt::ItemFlags flags() const { return itemFlags; }
    00087     void setFlags(Qt::ItemFlags flags);
    00088
    00089     inline QString text() const
    00090         { return data(Qt::DisplayRole).toString(); }
    00091     inline void setText(const QString &text);
    00092
    00093     inline QIcon icon() const
    00094         { return qvariant_cast<QIcon>(data(Qt::DecorationRole)); }
    00095     inline void setIcon(const QIcon &icon);
    00096
    00097     inline QString statusTip() const
    00098         { return data(Qt::StatusTipRole).toString(); }
    00099     inline void setStatusTip(const QString &statusTip);
    00100
    00101 #ifndef QT_NO_TOOLTIP
    00102     inline QString toolTip() const
    00103         { return data(Qt::ToolTipRole).toString(); }
    00104     inline void setToolTip(const QString &toolTip);
    00105 #endif
    00106
    00107 #ifndef QT_NO_WHATSTHIS
    00108     inline QString whatsThis() const
    00109         { return data(Qt::WhatsThisRole).toString(); }
    00110     inline void setWhatsThis(const QString &whatsThis);
    00111 #endif
    00112
    00113     inline QFont font() const
    00114         { return qvariant_cast<QFont>(data(Qt::FontRole)); }
    00115     inline void setFont(const QFont &font);
    00116
    00117     inline int textAlignment() const
    00118         { return data(Qt::TextAlignmentRole).toInt(); }
    00119     inline void setTextAlignment(int alignment)
    00120         { setData(Qt::TextAlignmentRole, alignment); }
    00121
    00122     inline QColor backgroundColor() const
    00123         { return qvariant_cast<QColor>(data(Qt::BackgroundColorRole)); }
    00124     virtual void setBackgroundColor(const QColor &color)
    00125         { setData(Qt::BackgroundColorRole, color); }
    00126
    00127     inline QBrush background() const
    00128         { return qvariant_cast<QBrush>(data(Qt::BackgroundRole)); }
    00129     inline void setBackground(const QBrush &brush)
    00130         { setData(Qt::BackgroundRole, brush); }
    00131
    00132     inline QColor textColor() const
    00133         { return qvariant_cast<QColor>(data(Qt::TextColorRole)); }
    00134     inline void setTextColor(const QColor &color)
    00135         { setData(Qt::TextColorRole, color); }
    00136
    00137     inline QBrush foreground() const
    00138         { return qvariant_cast<QBrush>(data(Qt::ForegroundRole)); }
    00139     inline void setForeground(const QBrush &brush)
    00140         { setData(Qt::ForegroundRole, brush); }
    00141
    00142     inline Qt::CheckState checkState() const
    00143         { return static_cast<Qt::CheckState>(data(Qt::CheckStateRole).toInt()); }
    00144     inline void setCheckState(Qt::CheckState state)
    00145         { setData(Qt::CheckStateRole, static_cast<int>(state)); }
    00146
    00147     inline QSize sizeHint() const
    00148         { return qvariant_cast<QSize>(data(Qt::SizeHintRole)); }
    00149     inline void setSizeHint(const QSize &size)
    00150         { setData(Qt::SizeHintRole, size); }
    00151
    00152     virtual QVariant data(int role) const;
    00153     virtual void setData(int role, const QVariant &value);
    00154
    00155     virtual bool operator<(const QListWidgetItem &other) const;
    00156
    00157 #ifndef QT_NO_DATASTREAM
    00158     virtual void read(QDataStream &in);
    00159     virtual void write(QDataStream &out) const;
    00160 #endif
    00161     QListWidgetItem &operator=(const QListWidgetItem &other);
    00162
    00163     inline int type() const { return rtti; }
    00164
    00165 private:
    00166     int rtti;
    00167     QVector<void *> dummy;
    00168     QListWidget *view;
    00169     QListWidgetItemPrivate *d;
    00170     Qt::ItemFlags itemFlags;
    00171 };
    00172
    00173 inline void QListWidgetItem::setText(const QString &atext)
    00174 { setData(Qt::DisplayRole, atext); }
    00175
    00176 inline void QListWidgetItem::setIcon(const QIcon &aicon)
    00177 { setData(Qt::DecorationRole, aicon); }
    00178
    00179 inline void QListWidgetItem::setStatusTip(const QString &astatusTip)
    00180 { setData(Qt::StatusTipRole, astatusTip); }
    00181
    00182 #ifndef QT_NO_TOOLTIP
    00183 inline void QListWidgetItem::setToolTip(const QString &atoolTip)
    00184 { setData(Qt::ToolTipRole, atoolTip); }
    00185 #endif
    00186
    00187 #ifndef QT_NO_WHATSTHIS
    00188 inline void QListWidgetItem::setWhatsThis(const QString &awhatsThis)
    00189 { setData(Qt::WhatsThisRole, awhatsThis); }
    00190 #endif
    00191
    00192 inline void QListWidgetItem::setFont(const QFont &afont)
    00193 { setData(Qt::FontRole, afont); }
    00194
    00195 #ifndef QT_NO_DATASTREAM
    00196 Q_GUI_EXPORT QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item);
    00197 Q_GUI_EXPORT QDataStream &operator>>(QDataStream &in, QListWidgetItem &item);
    00198 #endif
    00199
    00200 class QListWidgetPrivate;
    00201
    00202 class Q_GUI_EXPORT QListWidget : public QListView
    00203 {
    00204     Q_OBJECT
    00205     Q_PROPERTY(int count READ count)
    00206     Q_PROPERTY(int currentRow READ currentRow WRITE setCurrentRow NOTIFY currentRowChanged USER true)
    00207     Q_PROPERTY(bool sortingEnabled READ isSortingEnabled WRITE setSortingEnabled)
    00208
    00209     friend class QListWidgetItem;
    00210     friend class QListModel;
    00211 public:
    00212     explicit QListWidget(QWidget *parent = 0);
    00213     ~QListWidget();
    00214
    00215     QListWidgetItem *item(int row) const;
    00216     int row(const QListWidgetItem *item) const;
    00217     void insertItem(int row, QListWidgetItem *item);
    00218     void insertItem(int row, const QString &label);
    00219     void insertItems(int row, const QStringList &labels);
    00220     inline void addItem(const QString &label) { insertItem(count(), label); }
    00221     inline void addItem(QListWidgetItem *item);
    00222     inline void addItems(const QStringList &labels) { insertItems(count(), labels); }
    00223     QListWidgetItem *takeItem(int row);
    00224     int count() const;
    00225
    00226     QListWidgetItem *currentItem() const;
    00227     void setCurrentItem(QListWidgetItem *item);
    00228     void setCurrentItem(QListWidgetItem *item, QItemSelectionModel::SelectionFlags command);
    00229
    00230     int currentRow() const;
    00231     void setCurrentRow(int row);
    00232     void setCurrentRow(int row, QItemSelectionModel::SelectionFlags command);
    00233
    00234     QListWidgetItem *itemAt(const QPoint &p) const;
    00235     inline QListWidgetItem *itemAt(int x, int y) const;
    00236     QRect visualItemRect(const QListWidgetItem *item) const;
    00237
    00238     void sortItems(Qt::SortOrder order = Qt::AscendingOrder);
    00239     void setSortingEnabled(bool enable);
    00240     bool isSortingEnabled() const;
    00241
    00242     void editItem(QListWidgetItem *item);
    00243     void openPersistentEditor(QListWidgetItem *item);
    00244     void closePersistentEditor(QListWidgetItem *item);
    00245
    00246     QWidget *itemWidget(QListWidgetItem *item) const;
    00247     void setItemWidget(QListWidgetItem *item, QWidget *widget);
    00248     inline void removeItemWidget(QListWidgetItem *item);
    00249
    00250     bool isItemSelected(const QListWidgetItem *item) const;
    00251     void setItemSelected(const QListWidgetItem *item, bool select);
    00252     QList<QListWidgetItem*> selectedItems() const;
    00253     QList<QListWidgetItem*> findItems(const QString &text, Qt::MatchFlags flags) const;
    00254
    00255     bool isItemHidden(const QListWidgetItem *item) const;
    00256     void setItemHidden(const QListWidgetItem *item, bool hide);
    00257     void dropEvent(QDropEvent *event);
    00258
    00259 public Q_SLOTS:
    00260     void scrollToItem(const QListWidgetItem *item, QAbstractItemView::ScrollHint hint = EnsureVisible);
    00261     void clear();
    00262
    00263 Q_SIGNALS:
    00264     void itemPressed(QListWidgetItem *item);
    00265     void itemClicked(QListWidgetItem *item);
    00266     void itemDoubleClicked(QListWidgetItem *item);
    00267     void itemActivated(QListWidgetItem *item);
    00268     void itemEntered(QListWidgetItem *item);
    00269     void itemChanged(QListWidgetItem *item);
    00270
    00271     void currentItemChanged(QListWidgetItem *current, QListWidgetItem *previous);
    00272     void currentTextChanged(const QString &currentText);
    00273     void currentRowChanged(int currentRow);
    00274
    00275     void itemSelectionChanged();
    00276
    00277 protected:
    00278     bool event(QEvent *e);
    00279     virtual QStringList mimeTypes() const;
    00280     virtual QMimeData *mimeData(const QList<QListWidgetItem*> items) const;
    00281 #ifndef QT_NO_DRAGANDDROP
    00282     virtual bool dropMimeData(int index, const QMimeData *data, Qt::DropAction action);
    00283     virtual Qt::DropActions supportedDropActions() const;
    00284 #endif
    00285     QList<QListWidgetItem*> items(const QMimeData *data) const;
    00286
    00287     QModelIndex indexFromItem(QListWidgetItem *item) const;
    00288     QListWidgetItem *itemFromIndex(const QModelIndex &index) const;
    00289
    00290 private:
    00291     void setModel(QAbstractItemModel *model);
    00292     Qt::SortOrder sortOrder() const;
    00293
    00294     Q_DECLARE_PRIVATE(QListWidget)
    00295     Q_DISABLE_COPY(QListWidget)
    00296
    00297     Q_PRIVATE_SLOT(d_func(), void _q_emitItemPressed(const QModelIndex &index))
    00298     Q_PRIVATE_SLOT(d_func(), void _q_emitItemClicked(const QModelIndex &index))
    00299     Q_PRIVATE_SLOT(d_func(), void _q_emitItemDoubleClicked(const QModelIndex &index))
    00300     Q_PRIVATE_SLOT(d_func(), void _q_emitItemActivated(const QModelIndex &index))
    00301     Q_PRIVATE_SLOT(d_func(), void _q_emitItemEntered(const QModelIndex &index))
    00302     Q_PRIVATE_SLOT(d_func(), void _q_emitItemChanged(const QModelIndex &index))
    00303     Q_PRIVATE_SLOT(d_func(), void _q_emitCurrentItemChanged(const QModelIndex &previous, const QModelIndex &current))
    00304     Q_PRIVATE_SLOT(d_func(), void _q_sort())
    00305     Q_PRIVATE_SLOT(d_func(), void _q_dataChanged(const QModelIndex &topLeft, const QModelIndex &bottomRight))
    00306 };
    00307
    00308 inline void QListWidget::removeItemWidget(QListWidgetItem *aItem)
    00309 { setItemWidget(aItem, 0); }
    00310
    00311 inline void QListWidget::addItem(QListWidgetItem *aitem)
    00312 { insertItem(count(), aitem); }
    00313
    00314 inline QListWidgetItem *QListWidget::itemAt(int ax, int ay) const
    00315 { return itemAt(QPoint(ax, ay)); }
    00316
    00317 inline void QListWidgetItem::setSelected(bool aselect)
    00318 { if (view) view->setItemSelected(this, aselect); }
    00319
    00320 inline bool QListWidgetItem::isSelected() const
    00321 { return (view ? view->isItemSelected(this) : false); }
    00322
    00323 inline void QListWidgetItem::setHidden(bool ahide)
    00324 { if (view) view->setItemHidden(this, ahide); }
    00325
    00326 inline bool QListWidgetItem::isHidden() const
    00327 { return (view ? view->isItemHidden(this) : false); }
    00328
    00329 #endif // QT_NO_LISTWIDGET
    00330
    00331 QT_END_NAMESPACE
    00332
    00333 QT_END_HEADER
    00334
    00335 #endif // QLISTWIDGET_H