Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QTableWidgetItem Class Reference

The QTableWidgetItem class provides an item for use with the QTableWidget class. More...

#include <qtablewidget.h>

+ Collaboration diagram for QTableWidgetItem:

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)
 Constructs a copy of other.
 
virtual ~QTableWidgetItem ()
 Destroys the table item.
 
virtual QTableWidgetItemclone () const
 Creates a copy of the item.
 
QTableWidgettableWidget () const
 Returns the table widget that contains the item.
 
int row () const
 Returns the row of the item in the table.
 
int column () const
 Returns the column of the item in the table.
 
void setSelected (bool select)
 Sets the selected state of the item to select.
 
bool isSelected () const
 Returns true if the item is selected, otherwise returns false.
 
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
 Returns the brush used to render the item's background.
 
void setBackground (const QBrush &brush)
 Sets the item's background brush to the specified brush.
 
QBrush foreground () const
 Returns the brush used to render the item's foreground (e.g.
 
void setForeground (const QBrush &brush)
 Sets the item's foreground brush to the specified 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
 Returns the size hint set for the table item.
 
void setSizeHint (const QSize &size)
 Sets the size hint for the table item to be 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.
 
QTableWidgetItemoperator= (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.)

QDataStreamoperator>> (QDataStream &in, QTableWidgetItem &item)
 Reads a table widget item from stream in into item.
 
QDataStreamoperator<< (QDataStream &out, const QTableWidgetItem &item)
 Writes the table widget item item to stream out.
 

Detailed Description

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:

QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").arg(
pow(row, column+1)));
tableWidget->setItem(row, column, newItem);

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.

Member Enumeration Documentation

◆ ItemType

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.

See also
type()
Enumerator
Type 
UserType 

Definition at line 54 of file qtablewidget.h.

Constructor & Destructor Documentation

◆ QTableWidgetItem() [1/4]

QTableWidgetItem::QTableWidgetItem ( int type = Type)
explicit

Constructs a table item of the specified type that does not belong to any table.

See also
type()

Definition at line 1318 of file qtablewidget.cpp.

◆ QTableWidgetItem() [2/4]

QTableWidgetItem::QTableWidgetItem ( const QString & text,
int type = Type )
explicit

Constructs a table item with the given text.

See also
type()

Definition at line 1334 of file qtablewidget.cpp.

◆ QTableWidgetItem() [3/4]

QTableWidgetItem::QTableWidgetItem ( const QIcon & icon,
const QString & text,
int type = Type )
explicit

Constructs a table item with the given icon and text.

See also
type()

Definition at line 1351 of file qtablewidget.cpp.

◆ QTableWidgetItem() [4/4]

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().

See also
data(), flags()

Definition at line 1510 of file qtablewidget.cpp.

◆ ~QTableWidgetItem()

QTableWidgetItem::~QTableWidgetItem ( )
virtual

Destroys the table item.

Definition at line 1367 of file qtablewidget.cpp.

Member Function Documentation

◆ background()

QBrush QTableWidgetItem::background ( ) const
inline

Returns the brush used to render the item's background.

See also
foreground()

Definition at line 119 of file qtablewidget.h.

◆ checkState()

Qt::CheckState QTableWidgetItem::checkState ( ) const
inline

Returns the checked state of the table item.

See also
flags()

Definition at line 129 of file qtablewidget.h.

◆ clone()

QTableWidgetItem * QTableWidgetItem::clone ( ) const
virtual

Creates a copy of the item.

Definition at line 1377 of file qtablewidget.cpp.

◆ column()

int QTableWidgetItem::column ( ) const
inline

Returns the column of the item in the table.

If the item is not in a table, this function will return -1.

See also
row()

Definition at line 326 of file qtablewidget.h.

Referenced by testing.tools.encode_pdf_filter._Ascii85DecodePdfStream::close().

+ Here is the caller graph for this function:

◆ data()

QVariant QTableWidgetItem::data ( int role) const
virtual

Returns the item's data for the given role.

Definition at line 1418 of file qtablewidget.cpp.

◆ flags()

Qt::ItemFlags QTableWidgetItem::flags ( ) const
inline

Returns the flags used to describe the item.

These determine whether the item can be checked, edited, and selected.

See also
setFlags()

Definition at line 71 of file qtablewidget.h.

◆ font()

QFont QTableWidgetItem::font ( ) const
inline

Returns the font used to render the item's text.

See also
setFont()

Definition at line 98 of file qtablewidget.h.

◆ foreground()

QBrush QTableWidgetItem::foreground ( ) const
inline

Returns the brush used to render the item's foreground (e.g.

text).

See also
background()

Definition at line 124 of file qtablewidget.h.

◆ icon()

QIcon QTableWidgetItem::icon ( ) const
inline

Returns the item's icon.

See also
setIcon(), {QAbstractItemView::iconSize}{iconSize}

Definition at line 78 of file qtablewidget.h.

◆ isSelected()

bool QTableWidgetItem::isSelected ( ) const

Returns true if the item is selected, otherwise returns false.

See also
setSelected()

Definition at line 1078 of file qtablewidget.cpp.

◆ operator<()

bool QTableWidgetItem::operator< ( const QTableWidgetItem & other) const
virtual

Returns true if the item is less than the other item; otherwise returns false.

Definition at line 1432 of file qtablewidget.cpp.

◆ operator=()

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().

See also
data(), flags()

Definition at line 1525 of file qtablewidget.cpp.

◆ read()

void QTableWidgetItem::read ( QDataStream & in)
virtual

Reads the item from stream in.

See also
write()

Definition at line 1445 of file qtablewidget.cpp.

◆ row()

int QTableWidgetItem::row ( ) const
inline

Returns the row of the item in the table.

If the item is not in a table, this function will return -1.

See also
column()

Definition at line 323 of file qtablewidget.h.

◆ setBackground()

void QTableWidgetItem::setBackground ( const QBrush & brush)
inline

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.

See also
setForeground()

Definition at line 121 of file qtablewidget.h.

◆ setCheckState()

void QTableWidgetItem::setCheckState ( Qt::CheckState state)
inline

Sets the check state of the table item to be state.

Definition at line 131 of file qtablewidget.h.

◆ setData()

void QTableWidgetItem::setData ( int role,
const QVariant & value )
virtual

Sets the item's data for the given role to the specified value.

Note
The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.
See also
Qt::ItemDataRole, data()

Definition at line 1390 of file qtablewidget.cpp.

◆ setFlags()

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.

See also
flags()

Definition at line 1124 of file qtablewidget.cpp.

◆ setFont()

void QTableWidgetItem::setFont ( const QFont & font)
inline

Sets the font used to display the item's text to the given font.

See also
font(), setText(), setForeground()

Definition at line 182 of file qtablewidget.h.

◆ setForeground()

void QTableWidgetItem::setForeground ( const QBrush & brush)
inline

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.

See also
setBackground()

Definition at line 126 of file qtablewidget.h.

◆ setIcon()

void QTableWidgetItem::setIcon ( const QIcon & icon)
inline

Sets the item's icon to the icon specified.

See also
icon(), setText(), {QAbstractItemView::iconSize}{iconSize}

Definition at line 166 of file qtablewidget.h.

◆ setSelected()

void QTableWidgetItem::setSelected ( bool select)

Sets the selected state of the item to select.

See also
isSelected()

Definition at line 1096 of file qtablewidget.cpp.

◆ setSizeHint()

void QTableWidgetItem::setSizeHint ( const QSize & size)
inline

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.

◆ setStatusTip()

void QTableWidgetItem::setStatusTip ( const QString & statusTip)
inline

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.

See also
statusTip(), setToolTip(), setWhatsThis()

Definition at line 169 of file qtablewidget.h.

◆ setText()

void QTableWidgetItem::setText ( const QString & text)
inline

Sets the item's text to the text specified.

See also
text(), setFont(), setForeground()

Definition at line 163 of file qtablewidget.h.

◆ setTextAlignment()

void QTableWidgetItem::setTextAlignment ( Qt::Alignment alignment)
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.

See also
Qt::Alignment
Since
6.4

Sets the text alignment for the item's text to the alignment specified.

Definition at line 116 of file qtablewidget.h.

◆ sizeHint()

QSize QTableWidgetItem::sizeHint ( ) const
inline

Returns the size hint set for the table item.

Definition at line 134 of file qtablewidget.h.

◆ statusTip()

QString QTableWidgetItem::statusTip ( ) const
inline

Returns the item's status tip.

See also
setStatusTip()

Definition at line 82 of file qtablewidget.h.

◆ tableWidget()

QTableWidget * QTableWidgetItem::tableWidget ( ) const
inline

Returns the table widget that contains the item.

Definition at line 63 of file qtablewidget.h.

◆ text()

QString QTableWidgetItem::text ( ) const
inline

Returns the item's text.

See also
setText()

Definition at line 74 of file qtablewidget.h.

◆ textAlignment()

Qt::Alignment QTableWidgetItem::textAlignment ( ) const
inline

Returns the text alignment for the item's text.

Note
This function returns an int for historical reasons. It will be corrected to return Qt::Alignment in Qt 7.
See also
Qt::Alignment

Definition at line 106 of file qtablewidget.h.

◆ type()

int QTableWidgetItem::type ( ) const
inline

Returns the type passed to the QTableWidgetItem constructor.

Definition at line 150 of file qtablewidget.h.

◆ write()

void QTableWidgetItem::write ( QDataStream & out) const
virtual

Writes the item to stream out.

See also
read()

Definition at line 1455 of file qtablewidget.cpp.

Friends And Related Symbol Documentation

◆ operator<<()

QDataStream & operator<< ( QDataStream & out,
const QTableWidgetItem & item )
related

Writes the table widget item item to stream out.

This operator uses QTableWidgetItem::write().

See also
{Serializing Qt Data Types}

Definition at line 1494 of file qtablewidget.cpp.

◆ operator>>()

QDataStream & operator>> ( QDataStream & in,
QTableWidgetItem & item )
related

Reads a table widget item from stream in into item.

This operator uses QTableWidgetItem::read().

See also
{Serializing Qt Data Types}

Definition at line 1479 of file qtablewidget.cpp.

◆ QTableModel

friend class QTableModel
friend

Definition at line 52 of file qtablewidget.h.

◆ QTableWidget

friend class QTableWidget
friend

Definition at line 51 of file qtablewidget.h.


The documentation for this class was generated from the following files: