📄 qtablewidget.cpp
字号:
/*! \fn int QTableWidgetSelectionRange::rightColumn() const Returns the right column of the range. \sa leftColumn(), bottomRow(), columnCount()*//*! \since 4.1 \fn int QTableWidgetSelectionRange::rowCount() const Returns the number of rows in the range. This is equivalent to bottomRow() - topRow() + 1. \sa columnCount(), topRow(), bottomRow()*//*! \since 4.1 \fn int QTableWidgetSelectionRange::columnCount() const Returns the number of columns in the range. This is equivalent to rightColumn() - leftColumn() + 1. \sa rowCount(), leftColumn(), rightColumn()*//*! \class QTableWidgetItem \brief The QTableWidgetItem class provides an item for use with the QTableWidget class. \ingroup model-view Table items are used to hold pieces of information for table widgets. Items usually contain text, icons, or checkboxes The QTableWidgetItem class is a convenience class that replaces the \c QTableItem class in Qt 3. It provides an item for use with the QTableWidget class. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers: \quotefile snippets/qtablewidget-using/mainwindow.cpp \skipto QTableWidgetItem *newItem \printuntil tableWidget->setItem( Each item can have its own background brush which is set with the setBackground() function. The current background brush can be found with background(). The text label for each item can be rendered with its own font and brush. These are specified with the setFont() and setForeground() functions, and read with font() and foreground(). By default, items are enabled, editable, selectable, checkable, and can be used both as the source of a drag and drop operation and as a drop target. Each item's flags can be changed by calling setFlags() with the appropriate value (see \l{Qt::ItemFlags}). Checkable items can be checked and unchecked with the setChecked() function. The corresponding checked() function indicates whether the item is currently checked. \section1 Subclassing When subclassing QTableWidgetItem 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 QTableWidget, {Model/View Programming}, QListWidgetItem, QTreeWidgetItem*//*! \fn int QTableWidgetItem::row() const \since 4.2 Returns the row of the item in the table. If the item is not in a table, this function will return -1. \sa column()*//*! \fn int QTableWidgetItem::column() const \since 4.2 Returns the column of the item in the table. If the item is not in a table, this function will return -1. \sa row()*//*! \fn void QTableWidgetItem::setSelected(bool select) \since 4.2 Sets the selected state of the item to \a select. \sa isSelected()*//*! \fn bool QTableWidgetItem::isSelected() const \since 4.2 Returns true if the item is selected, otherwise returns false. \sa setSelected()*//*! \fn QSize QTableWidgetItem::sizeHint() const \since 4.1 Returns the size hint set for the table item.*//*! \fn void QTableWidgetItem::setSizeHint(const QSize &size) \since 4.1 Sets the size hint for the table 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 Qt::CheckState QTableWidgetItem::checkState() const Returns the checked state of the table item. \sa flags()*//*! \fn void QTableWidgetItem::setCheckState(Qt::CheckState state) Sets the check state of the table item to be \a state.*//*! \fn QTableWidget *QTableWidgetItem::tableWidget() const Returns the table widget that contains the item.*//*! \fn Qt::ItemFlags QTableWidgetItem::flags() const Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected. \sa setFlags()*//*! \fn void QTableWidgetItem::setFlags(Qt::ItemFlags flags) Sets the flags for the item to the given \a flags. These determine whether the item can be selected or modified. \sa flags()*/void QTableWidgetItem::setFlags(Qt::ItemFlags aflags){ itemFlags = aflags; if (QTableModel *model = (view ? ::qobject_cast<QTableModel*>(view->model()) : 0)) model->itemChanged(this);}/*! \fn QString QTableWidgetItem::text() const Returns the item's text. \sa setText()*//*! \fn void QTableWidgetItem::setText(const QString &text) Sets the item's text to the \a text specified. \sa text() setFont() setForeground()*//*! \fn QIcon QTableWidgetItem::icon() const Returns the item's icon. \sa setIcon(), {QAbstractItemView::iconSize}{iconSize}*//*! \fn void QTableWidgetItem::setIcon(const QIcon &icon) Sets the item's icon to the \a icon specified. \sa icon(), setText(), {QAbstractItemView::iconSize}{iconSize}*//*! \fn QString QTableWidgetItem::statusTip() const Returns the item's status tip. \sa setStatusTip()*//*! \fn void QTableWidgetItem::setStatusTip(const QString &statusTip) Sets the item's status tip to the string specified by \a statusTip. \sa statusTip() setToolTip() setWhatsThis()*//*! \fn QString QTableWidgetItem::toolTip() const Returns the item's tooltip. \sa setToolTip()*//*! \fn void QTableWidgetItem::setToolTip(const QString &toolTip) Sets the item's tooltip to the string specified by \a toolTip. \sa toolTip() setStatusTip() setWhatsThis()*//*! \fn QString QTableWidgetItem::whatsThis() const Returns the item's "What's This?" help. \sa setWhatsThis()*//*! \fn void QTableWidgetItem::setWhatsThis(const QString &whatsThis) Sets the item's "What's This?" help to the string specified by \a whatsThis. \sa whatsThis() setStatusTip() setToolTip()*//*! \fn QFont QTableWidgetItem::font() const Returns the font used to render the item's text. \sa setFont()*//*! \fn void QTableWidgetItem::setFont(const QFont &font) Sets the font used to display the item's text to the given \a font. \sa font() setText() setForeground()*//*! \fn QColor QTableWidgetItem::backgroundColor() const \obsolete This function is deprecated. Use background() instead.*//*! \fn void QTableWidgetItem::setBackgroundColor(const QColor &color) \obsolete This function is deprecated. Use setBackground() instead.*//*! \fn QBrush QTableWidgetItem::background() const \since 4.2 Returns the brush used to render the item's background. \sa foreground()*//*! \fn void QTableWidgetItem::setBackground(const QBrush &brush) \since 4.2 Sets the item's background brush to the specified \a brush. \sa setForeground()*//*! \fn QColor QTableWidgetItem::textColor() const \obsolete This function is deprecated. Use foreground() instead.*//*! \fn void QTableWidgetItem::setTextColor(const QColor &color) \obsolete This function is deprecated. Use setForeground() instead.*//*! \fn QBrush QTableWidgetItem::foreground() const \since 4.2 Returns the brush used to render the item's foreground (e.g. text). \sa background()*//*! \fn void QTableWidgetItem::setForeground(const QBrush &brush) \since 4.2 Sets the item's foreground brush to the specified \a brush. \sa setBackground()*//*! \fn int QTableWidgetItem::textAlignment() const Returns the text alignment for the item's text. \sa Qt::Alignment*//*! \fn void QTableWidgetItem::setTextAlignment(int alignment) Sets the text alignment for the item's text to the \a alignment specified. \sa Qt::Alignment*//*! Constructs a table item of the specified \a type that does not belong to any table. \sa type()*/QTableWidgetItem::QTableWidgetItem(int type) : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)), itemFlags(Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled){}/*! Constructs a table item with the given \a text. \sa type()*/QTableWidgetItem::QTableWidgetItem(const QString &text, int type) : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)), itemFlags(Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled){ setData(Qt::DisplayRole, text);}/*! Constructs a table item with the given \a icon and \a text. \sa type()*/QTableWidgetItem::QTableWidgetItem(const QIcon &icon, const QString &text, int type) : rtti(type), view(0), d(new QTableWidgetItemPrivate(this)), itemFlags(Qt::ItemIsEditable |Qt::ItemIsSelectable |Qt::ItemIsUserCheckable |Qt::ItemIsEnabled |Qt::ItemIsDragEnabled |Qt::ItemIsDropEnabled){ setData(Qt::DecorationRole, icon); setData(Qt::DisplayRole, text);}/*! Destroys the table item.*/QTableWidgetItem::~QTableWidgetItem(){ if (QTableModel *model = (view ? ::qobject_cast<QTableModel*>(view->model()) : 0)) model->removeItem(this); view = 0; delete d;}/*! Creates a copy of the item.*/QTableWidgetItem *QTableWidgetItem::clone() const{ return new QTableWidgetItem(*this);}/*! Sets the item's data for the given \a role to the specified \a value. \sa Qt::ItemDataRole, data()*/void QTableWidgetItem::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[i].value == value) return; values[i].value = value; found = true; break; } } if (!found) values.append(QWidgetItemData(role, value)); if (QTableModel *model = (view ? ::qobject_cast<QTableModel*>(view->model()) : 0)) model->itemChanged(this);}/*! Returns the item's data for the given \a role.*/QVariant QTableWidgetItem::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 the item is less than the \a other item; otherwise returns false.*/bool QTableWidgetItem::operator<(const QTableWidgetItem &other) const{ const QVariant v1 = data(Qt::DisplayRole), v2 = other.data(Qt::DisplayRole);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -