![]() |
Qt 6.x
The Qt SDK
|
The QTableWidgetItem class provides an item for use with the QTableWidget class. More...
#include <qtablewidget.h>
Public Types | |
enum | ItemType { Type = 0 , UserType = 1000 } |
This enum describes the types that are used to describe table widget items. More... | |
Public Member Functions | |
QTableWidgetItem (int type=Type) | |
Constructs a table item of the specified type that does not belong to any table. | |
QTableWidgetItem (const QString &text, int type=Type) | |
Constructs a table item with the given text. | |
QTableWidgetItem (const QIcon &icon, const QString &text, int type=Type) | |
Constructs a table item with the given icon and text. | |
QTableWidgetItem (const QTableWidgetItem &other) | |
virtual | ~QTableWidgetItem () |
Destroys the table item. | |
virtual QTableWidgetItem * | clone () const |
Creates a copy of the item. | |
QTableWidget * | tableWidget () const |
Returns the table widget that contains the item. | |
int | row () const |
int | column () const |
void | setSelected (bool select) |
bool | isSelected () const |
Qt::ItemFlags | flags () const |
Returns the flags used to describe the item. | |
void | setFlags (Qt::ItemFlags flags) |
Sets the flags for the item to the given flags. | |
QString | text () const |
Returns the item's text. | |
void | setText (const QString &text) |
Sets the item's text to the text specified. | |
QIcon | icon () const |
Returns the item's icon. | |
void | setIcon (const QIcon &icon) |
Sets the item's icon to the icon specified. | |
QString | statusTip () const |
Returns the item's status tip. | |
void | setStatusTip (const QString &statusTip) |
Sets the status tip for the table item to the text specified by statusTip. | |
QFont | font () const |
Returns the font used to render the item's text. | |
void | setFont (const QFont &font) |
Sets the font used to display the item's text to the given font. | |
Qt::Alignment | textAlignment () const |
void | setTextAlignment (Qt::Alignment alignment) |
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument. | |
QBrush | background () const |
void | setBackground (const QBrush &brush) |
QBrush | foreground () const |
void | setForeground (const QBrush &brush) |
Qt::CheckState | checkState () const |
Returns the checked state of the table item. | |
void | setCheckState (Qt::CheckState state) |
Sets the check state of the table item to be state. | |
QSize | sizeHint () const |
void | setSizeHint (const QSize &size) |
virtual QVariant | data (int role) const |
Returns the item's data for the given role. | |
virtual void | setData (int role, const QVariant &value) |
Sets the item's data for the given role to the specified value. | |
virtual bool | operator< (const QTableWidgetItem &other) const |
Returns true if the item is less than the other item; otherwise returns false. | |
virtual void | read (QDataStream &in) |
Reads the item from stream in. | |
virtual void | write (QDataStream &out) const |
Writes the item to stream out. | |
QTableWidgetItem & | operator= (const QTableWidgetItem &other) |
Assigns other's data and flags to this item. | |
int | type () const |
Returns the type passed to the QTableWidgetItem constructor. | |
Friends | |
class | QTableWidget |
class | QTableModel |
Related Symbols | |
(Note that these are not member symbols.) | |
QDataStream & | operator>> (QDataStream &in, QTableWidgetItem &item) |
Reads a table widget item from stream in into item. | |
QDataStream & | operator<< (QDataStream &out, const QTableWidgetItem &item) |
Writes the table widget item item to stream out. | |
The QTableWidgetItem class provides an item for use with the QTableWidget class.
\inmodule QtWidgets
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 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:
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 setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.
Definition at line 49 of file qtablewidget.h.
This enum describes the types that are used to describe table widget items.
\value Type The default type for table widget items. \value UserType The minimum value for custom types. Values below UserType are reserved by Qt.
You can define new user types in QTableWidgetItem subclasses to ensure that custom items are treated specially.
Enumerator | |
---|---|
Type | |
UserType |
Definition at line 54 of file qtablewidget.h.
|
explicit |
Constructs a table item of the specified type that does not belong to any table.
Definition at line 1307 of file qtablewidget.cpp.
Constructs a table item with the given text.
Definition at line 1323 of file qtablewidget.cpp.
References Qt::DisplayRole, setData(), and text().
|
explicit |
Constructs a table item with the given icon and text.
Definition at line 1340 of file qtablewidget.cpp.
References Qt::DecorationRole, Qt::DisplayRole, icon(), setData(), and text().
QTableWidgetItem::QTableWidgetItem | ( | const QTableWidgetItem & | other | ) |
Constructs a copy of other. Note that type() and tableWidget() are not copied.
This function is useful when reimplementing clone().
Definition at line 1501 of file qtablewidget.cpp.
|
virtual |
|
inline |
Returns the brush used to render the item's background.
Definition at line 119 of file qtablewidget.h.
References Qt::BackgroundRole.
|
inline |
Returns the checked state of the table item.
Definition at line 129 of file qtablewidget.h.
References Qt::CheckStateRole.
|
virtual |
Creates a copy of the item.
Definition at line 1366 of file qtablewidget.cpp.
Referenced by QTableModel::createItem().
|
inline |
Returns the column of the item in the table. If the item is not in a table, this function will return -1.
Definition at line 336 of file qtablewidget.h.
References view.
|
virtual |
Returns the item's data for the given role.
Definition at line 1407 of file qtablewidget.cpp.
References Qt::DisplayRole, Qt::EditRole, and QVariant::value().
Referenced by QTableModel::data(), QTableModel::headerData(), and QTableModel::setItemData().
|
inline |
Returns the flags used to describe the item.
These determine whether the item can be checked, edited, and selected.
Definition at line 71 of file qtablewidget.h.
|
inline |
Returns the font used to render the item's text.
Definition at line 98 of file qtablewidget.h.
References Qt::FontRole.
|
inline |
Returns the brush used to render the item's foreground (e.g. text).
Definition at line 124 of file qtablewidget.h.
References Qt::ForegroundRole.
|
inline |
Returns the item's icon.
Definition at line 78 of file qtablewidget.h.
References Qt::DecorationRole.
Referenced by QTableWidgetItem().
bool QTableWidgetItem::isSelected | ( | ) | const |
Returns true
if the item is selected, otherwise returns false
.
Definition at line 1062 of file qtablewidget.cpp.
References QAbstractTableModel::index(), QItemSelectionModel::isSelected(), model, QAbstractItemView::model(), and QAbstractItemView::selectionModel().
|
virtual |
Returns true
if the item is less than the other item; otherwise returns false.
Definition at line 1421 of file qtablewidget.cpp.
References Qt::DisplayRole, other(), and QAbstractItemModelPrivate::variantLessThan().
QTableWidgetItem & QTableWidgetItem::operator= | ( | const QTableWidgetItem & | other | ) |
Assigns other's data and flags to this item.
Note that type() and tableWidget() are not copied.
This function is useful when reimplementing clone().
Definition at line 1516 of file qtablewidget.cpp.
References other().
|
virtual |
|
inline |
Returns the row of the item in the table. If the item is not in a table, this function will return -1.
Definition at line 333 of file qtablewidget.h.
References view.
Sets the item's background brush to the specified brush. Setting a default-constructed brush will let the view use the default color from the style.
Definition at line 121 of file qtablewidget.h.
References Qt::BackgroundRole, Qt::NoBrush, and setData().
|
inline |
Sets the check state of the table item to be state.
Definition at line 131 of file qtablewidget.h.
References Qt::CheckStateRole, setData(), and state.
Sets the item's data for the given role to the specified value.
Definition at line 1379 of file qtablewidget.cpp.
References Qt::DisplayRole, Qt::EditRole, i, and model.
Referenced by QTableWidgetItem(), QTableWidgetItem(), QTableModel::setData(), setFont(), QTableModel::setHeaderData(), setIcon(), QTableModel::setItemData(), setStatusTip(), and setText().
void QTableWidgetItem::setFlags | ( | Qt::ItemFlags | flags | ) |
Sets the flags for the item to the given flags.
These determine whether the item can be selected or modified.
Definition at line 1109 of file qtablewidget.cpp.
References model.
Sets the font used to display the item's text to the given font.
Definition at line 182 of file qtablewidget.h.
References Qt::FontRole, and setData().
Sets the item's foreground brush to the specified brush. Setting a default-constructed brush will let the view use the default color from the style.
Definition at line 126 of file qtablewidget.h.
References Qt::ForegroundRole, Qt::NoBrush, and setData().
Sets the item's icon to the icon specified.
Definition at line 166 of file qtablewidget.h.
References Qt::DecorationRole, and setData().
void QTableWidgetItem::setSelected | ( | bool | select | ) |
Sets the selected state of the item to select.
Definition at line 1081 of file qtablewidget.cpp.
References QItemSelectionModel::Deselect, QAbstractTableModel::index(), model, QAbstractItemView::model(), QItemSelectionModel::Select, QItemSelectionModel::select(), select(), and QAbstractItemView::selectionModel().
Sets the size hint for the table item to be size. If no size hint is set or size is invalid, the item delegate will compute the size hint based on the item data.
Definition at line 136 of file qtablewidget.h.
References setData(), and Qt::SizeHintRole.
Sets the status tip for the table item to the text specified by statusTip.
QTableWidget mouse tracking needs to be enabled for this feature to work.
Definition at line 169 of file qtablewidget.h.
References setData(), and Qt::StatusTipRole.
Sets the item's text to the text specified.
Definition at line 163 of file qtablewidget.h.
References Qt::DisplayRole, and setData().
Referenced by MainWindow::averageItems(), and MainWindow::sumItems().
|
inline |
\obsolete [6.4] Use the overload that takes a Qt::Alignment argument.
Sets the text alignment for the item's text to the alignment specified.
Sets the text alignment for the item's text to the alignment specified.
Definition at line 116 of file qtablewidget.h.
References alignment, QVariant::fromValue(), setData(), and Qt::TextAlignmentRole.
|
inline |
Returns the size hint set for the table item.
Definition at line 134 of file qtablewidget.h.
References Qt::SizeHintRole.
|
inline |
Returns the item's status tip.
Definition at line 82 of file qtablewidget.h.
References Qt::StatusTipRole.
|
inline |
Returns the table widget that contains the item.
Definition at line 63 of file qtablewidget.h.
References view.
|
inline |
Returns the item's text.
Definition at line 74 of file qtablewidget.h.
References Qt::DisplayRole.
Referenced by QTableWidgetItem(), and QTableWidgetItem().
|
inline |
Returns the text alignment for the item's text.
Definition at line 106 of file qtablewidget.h.
References Qt::TextAlignmentRole.
|
inline |
Returns the type passed to the QTableWidgetItem constructor.
Definition at line 150 of file qtablewidget.h.
|
virtual |
Writes the item to stream out.
Definition at line 1444 of file qtablewidget.cpp.
References out.
|
related |
Writes the table widget item item to stream out.
This operator uses QTableWidgetItem::write().
Definition at line 1483 of file qtablewidget.cpp.
|
related |
Reads a table widget item from stream in into item.
This operator uses QTableWidgetItem::read().
Definition at line 1468 of file qtablewidget.cpp.
References item.
|
friend |
Definition at line 52 of file qtablewidget.h.
|
friend |
Definition at line 51 of file qtablewidget.h.