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

📄 qlistwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 4 页
字号:
    List items are typically used to display text() and an icon(). These are    set with the setText() and setIcon() functions. The appearance of the text    can be customized with setFont(), setForeground(), and setBackground().    Text in list items can be aligned using the setTextAlignment() function.    Tooltips, status tips and "What's This?" help can be added to list items    with setToolTip(), setStatusTip(), and setWhatsThis().    By default, items are enabled, selectable, checkable, and can be the source    of a drag and drop operation.    Each item's flags can be changed by calling setFlags() with the appropriate    value (see \l{Qt::ItemFlags}). Checkable items can be checked, unchecked and    partially checked with the setCheckState() function. The corresponding    checkState() function indicates what check state the item currently has.    The isHidden() function can be used to determine whether the    item is hidden.  Items can be hidden with setHidden().    \section1 Subclassing    When subclassing QListWidgetItem to provide custom items, it is possible to    define new types for them so that they can be distinguished from standard    items. The constructors for subclasses that require this feature need to    call the base class constructor with a new type value equal to or greater    than \l UserType.    \sa QListWidget, {Model/View Programming}, QTreeWidgetItem, QTableWidgetItem*//*!    \enum QListWidgetItem::ItemType    This enum describes the types that are used to describe list widget items.    \value Type     The default type for list widget items.    \value UserType The minimum value for custom types. Values below UserType are                    reserved by Qt.    You can define new user types in QListWidgetItem subclasses to ensure that    custom items are treated specially.    \sa type()*//*!    \fn int QListWidgetItem::type() const    Returns the type passed to the QListWidgetItem constructor.*//*!    \fn QListWidget *QListWidgetItem::listWidget() const    Returns the list widget that contains the item.*//*!  \fn void QListWidgetItem::setSelected(bool select)  \since 4.2  Sets the selected state of the item to \a select.  \sa isSelected()*//*!  \fn bool QListWidgetItem::isSelected() const  \since 4.2  Returns true if the item is selected, otherwise returns false.  \sa setSelected()*//*!  \fn void QListWidgetItem::setHidden(bool hide)  \since 4.2  Hides the item if \a hide is true, otherwise shows the item.  \sa isHidden()*//*!  \fn bool QListWidgetItem::isHidden() const  \since 4.2  Returns true if the item is hidden, otherwise returns false.  \sa setHidden()*//*!    \fn QListWidgetItem::QListWidgetItem(QListWidget *parent, int type)    Constructs an empty list widget item of the specified \a type with the    given \a parent.    If the parent is not specified, the item will need to be inserted into a    list widget with QListWidget::insertItem().    \sa type()*/QListWidgetItem::QListWidgetItem(QListWidget *view, int type)    : rtti(type), view(view), d(new QListWidgetItemPrivate(this)),      itemFlags(Qt::ItemIsSelectable                |Qt::ItemIsUserCheckable                |Qt::ItemIsEnabled                |Qt::ItemIsDragEnabled){    if (QListModel *model = (view ? ::qobject_cast<QListModel*>(view->model()) : 0))        model->insert(model->rowCount(), this);}/*!    \fn QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *parent, int type)    Constructs an empty list widget item of the specified \a type with the    given \a text and \a parent.    If the parent is not specified, the item will need to be inserted into a    list widget with QListWidget::insertItem().    \sa type()*/QListWidgetItem::QListWidgetItem(const QString &text, QListWidget *view, int type)    : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),      itemFlags(Qt::ItemIsSelectable                |Qt::ItemIsUserCheckable                |Qt::ItemIsEnabled                |Qt::ItemIsDragEnabled){    setData(Qt::DisplayRole, text);    this->view = view;    if (QListModel *model = (view ? ::qobject_cast<QListModel*>(view->model()) : 0))        model->insert(model->rowCount(), this);}/*!    \fn QListWidgetItem::QListWidgetItem(const QIcon &icon, const QString &text, QListWidget *parent, int type)    Constructs an empty list widget item of the specified \a type with the    given \a icon, \a text and \a parent.    If the parent is not specified, the item will need to be inserted into a    list widget with QListWidget::insertItem().    \sa type()*/QListWidgetItem::QListWidgetItem(const QIcon &icon,const QString &text,                                 QListWidget *view, int type)    : rtti(type), view(0), d(new QListWidgetItemPrivate(this)),      itemFlags(Qt::ItemIsSelectable                |Qt::ItemIsUserCheckable                |Qt::ItemIsEnabled                |Qt::ItemIsDragEnabled){    setData(Qt::DisplayRole, text);    setData(Qt::DecorationRole, icon);    this->view = view;    if (QListModel *model = (view ? ::qobject_cast<QListModel*>(view->model()) : 0))        model->insert(model->rowCount(), this);}/*!  Destroys the list item.*/QListWidgetItem::~QListWidgetItem(){    if (QListModel *model = (view ? ::qobject_cast<QListModel*>(view->model()) : 0))        model->remove(this);    delete d;}/*!  Creates an exact copy of the item.*/QListWidgetItem *QListWidgetItem::clone() const{    return new QListWidgetItem(*this);}/*!  This function sets the data for a given \a role to the given \a value (see  \l{Qt::ItemDataRole}). Reimplement this function if you need  extra roles or special behavior for certain roles.  \sa Qt::ItemDataRole, data()*/void QListWidgetItem::setData(int role, const QVariant &value){    bool found = false;    role = (role == Qt::EditRole ? Qt::DisplayRole : role);    for (int i = 0; i < values.count(); ++i) {        if (values.at(i).role == role) {            if (values.at(i).value == value)                return;            values[i].value = value;            found = true;            break;        }    }    if (!found)        values.append(QWidgetItemData(role, value));    if (QListModel *model = (view ? ::qobject_cast<QListModel*>(view->model()) : 0))        model->itemChanged(this);}/*!   This function returns the item's data for a given \a role (see   Qt::ItemDataRole). Reimplement this function if you need   extra roles or special behavior for certain roles.*/QVariant QListWidgetItem::data(int role) const{    role = (role == Qt::EditRole ? Qt::DisplayRole : role);    for (int i = 0; i < values.count(); ++i)        if (values.at(i).role == role)            return values.at(i).value;    return QVariant();}/*!  Returns true if this item's text is less then \a other item's text;  otherwise returns false.*/bool QListWidgetItem::operator<(const QListWidgetItem &other) const{    return text() < other.text();}#ifndef QT_NO_DATASTREAM/*!    Reads the item from stream \a in.    \sa write()*/void QListWidgetItem::read(QDataStream &in){    in >> values;}/*!    Writes the item to stream \a out.    \sa read()*/void QListWidgetItem::write(QDataStream &out) const{    out << values;}/*!    \since 4.1    Constructs a copy of \a other. Note that type() and listWidget()    are not copied.    This function is useful when reimplementing clone().    \sa data(), flags()*/QListWidgetItem::QListWidgetItem(const QListWidgetItem &other)    : rtti(Type), values(other.values), view(0),      d(new QListWidgetItemPrivate(this)),      itemFlags(other.itemFlags){}/*!    Assigns \a other's data and flags to this item. Note that type()    and listWidget() are not copied.    This function is useful when reimplementing clone().    \sa data(), flags()*/QListWidgetItem &QListWidgetItem::operator=(const QListWidgetItem &other){    values = other.values;    itemFlags = other.itemFlags;    return *this;}/*!    \relates QListWidgetItem    Writes the list widget item \a item to stream \a out.    This operator uses QListWidgetItem::write().    \sa {Format of the QDataStream Operators}*/QDataStream &operator<<(QDataStream &out, const QListWidgetItem &item){    item.write(out);    return out;}/*!    \relates QListWidgetItem    Reads a list widget item from stream \a in into \a item.    This operator uses QListWidgetItem::read().    \sa {Format of the QDataStream Operators}*/QDataStream &operator>>(QDataStream &in, QListWidgetItem &item){    item.read(in);    return in;}#endif // QT_NO_DATASTREAM/*!  \fn Qt::ItemFlags QListWidgetItem::flags() const  Returns the item flags for this item (see \l{Qt::ItemFlags}).*//*!    \fn QString QListWidgetItem::text() const    Returns the list item's text.    \sa setText()*//*!    \fn QIcon QListWidgetItem::icon() const    Returns the list item's icon.    \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}*//*!    \fn QString QListWidgetItem::statusTip() const    Returns the list item's status tip.    \sa setStatusTip()*//*!    \fn QString QListWidgetItem::toolTip() const    Returns the list item's tooltip.    \sa setToolTip() statusTip() whatsThis()*//*!    \fn QString QListWidgetItem::whatsThis() const    Returns the list item's "What's This?" help text.    \sa setWhatsThis() statusTip() toolTip()*//*!  \fn QFont QListWidgetItem::font() const  Returns the font used to display this list item's text.*//*!  \fn int QListWidgetItem::textAlignment() const  Returns the text alignment for the list item (see \l{Qt::AlignmentFlag}).*//*!    \fn QColor QListWidgetItem::backgroundColor() const    \obsolete    This function is deprecated. Use background() instead.*//*!    \fn QBrush QListWidgetItem::background() const    \since 4.2    Returns the brush used to display the list item's background.    \sa setBackground() foreground()*//*!    \fn QColor QListWidgetItem::textColor() const    \obsolete    Returns the color used to display the list item's text.    This function is deprecated. Use foreground() instead.*//*!    \fn QBrush QListWidgetItem::foreground() const    \since 4.2    Returns the brush used to display the list item's foreground (e.g. text).    \sa setForeground() background()*//*!    \fn Qt::CheckState QListWidgetItem::checkState() const    Returns the checked state of the list item (see \l{Qt::CheckState}).    \sa flags()*//*!  \fn QSize QListWidgetItem::sizeHint() const  \since 4.1  Returns the size hint set for the list item.*//*!  \fn void QListWidgetItem::setSizeHint(const QSize &size)  \since 4.1  Sets the size hint for the list item to be \a size.  If no size hint is set, the item delegate will compute the  size hint based on the item data.*//*!  \fn void QListWidgetItem::setFlags(Qt::ItemFlags flags)  Sets the item flags for the list item to \a flags (see  \l{Qt::ItemFlags}).*/void QListWidgetItem::setFlags(Qt::ItemFlags aflags) {    itemFlags = aflags;    if (QListModel *model = (view ? ::qobject_cast<QListModel*>(view->model()) : 0))        model->itemChanged(this);}/*!    \fn void QListWidgetItem::setText(const QString &text)    Sets the text for the list widget item's to the given \a text.    \sa text()*//*!    \fn void QListWidgetItem::setIcon(const QIcon &icon)    Sets the icon for the list item to the given \a icon.    \sa icon(), text(), {QAbstractItemView::iconSize}{iconSize}*/

⌨️ 快捷键说明

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