CopperSpice API  1.9.1
QTableWidgetItem Class Reference

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

Public Types

enum  ItemType
 

Public Methods

 QTableWidgetItem (const QIcon &icon, const QString &text, int type=Type)
 
 QTableWidgetItem (const QString &text, int type=Type)
 
 QTableWidgetItem (const QTableWidgetItem &other)
 
 QTableWidgetItem (int type=Type)
 
virtual ~QTableWidgetItem ()
 
QBrush background () const
 
QColor backgroundColor () const
 
Qt::CheckState checkState () const
 
virtual QTableWidgetItem * clone () const
 
int column () const
 
virtual QVariant data (int role) const
 
Qt::ItemFlags flags () const
 
QFont font () const
 
QBrush foreground () const
 
QIcon icon () const
 
bool isSelected () const
 
virtual bool operator< (const QTableWidgetItem &other) const
 
QTableWidgetItem & operator= (const QTableWidgetItem &other)
 
virtual void read (QDataStream &in)
 
int row () const
 
void setBackground (const QBrush &brush)
 
void setBackgroundColor (const QColor &color)
 
void setCheckState (Qt::CheckState state)
 
virtual void setData (int role, const QVariant &value)
 
void setFlags (Qt::ItemFlags flags)
 
void setFont (const QFont &font)
 
void setForeground (const QBrush &brush)
 
void setIcon (const QIcon &icon)
 
void setSelected (bool select)
 
void setSizeHint (const QSize &size)
 
void setStatusTip (const QString &statusTip)
 
void setText (const QString &text)
 
void setTextAlignment (int alignment)
 
void setTextColor (const QColor &color)
 
void setToolTip (const QString &toolTip)
 
void setWhatsThis (const QString &whatsThis)
 
QSize sizeHint () const
 
QString statusTip () const
 
QTableWidgettableWidget () const
 
QString text () const
 
int textAlignment () const
 
QColor textColor () const
 
QString toolTip () const
 
int type () const
 
QString whatsThis () const
 
virtual void write (QDataStream &out) const
 

Friends

class QTableWidget
 

Related Functions

These are not member functions

QDataStreamoperator<< (QDataStream &out, const QTableWidgetItem &item)
 
QDataStreamoperator>> (QDataStream &in, QTableWidgetItem &item)
 

Detailed Description

The QTableWidgetItem class provides an item for use with the QTableWidget class. Table items are used to hold pieces of information for table widgets. Items usually contain text, icons, or checkboxes. Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers as shown below.

QTableWidgetItem *newItem = new QTableWidgetItem(tr("%1").formatArg(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 Qt::ItemFlags). Checkable items can be checked and unchecked with the setCheckState() function. The corresponding checkState() function indicates whether the item is currently checked.

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 UserType.

See also
QTableWidget, QListWidgetItem, QTreeWidgetItem, Model/View Architecture

Member Enumeration Documentation

This enum describes the types that are used to describe table widget items. You can define new user types in QTableWidgetItem subclasses to ensure that custom items are treated specially.

ConstantValueDescription
QTableWidgetItem::Type0 The default type for table widget items.
QTableWidgetItem::UserType1000 The minimum value for custom types. Values below UserType are reserved for CopperSpice.
See also
type()

Constructor & Destructor Documentation

QTableWidgetItem::QTableWidgetItem ( int  type = Type)
explicit

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

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

Constructs a table item with the given text.

See also
type()
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()
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()
QTableWidgetItem::~QTableWidgetItem ( )
virtual

Destroys the table item.

Method Documentation

QBrush QTableWidgetItem::background ( ) const
inline

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

See also
setBackground(), foreground()
QColor QTableWidgetItem::backgroundColor ( ) const
inlinedeprecated
Qt::CheckState QTableWidgetItem::checkState ( ) const
inline

Returns the checked state of the table item.

See also
setCheckState(), flags()
QTableWidgetItem * QTableWidgetItem::clone ( ) const
virtual

Creates a copy of the item.

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()
QVariant QTableWidgetItem::data ( int  role) const
virtual

Returns the item's data for the given role.

See also
setData()
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()
QFont QTableWidgetItem::font ( ) const
inline

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

See also
setFont()
QBrush QTableWidgetItem::foreground ( ) const
inline

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

See also
setForeground(), background()
QIcon QTableWidgetItem::icon ( ) const
inline

Returns the item's icon.

See also
setIcon(), QAbstractItemView::iconSize
bool QTableWidgetItem::isSelected ( ) const
inline

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

See also
setSelected()
bool QTableWidgetItem::operator< ( const QTableWidgetItem &  other) const
virtual

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

QTableWidgetItem & QTableWidgetItem::operator= ( const QTableWidgetItem &  other)

Copy assigns from other and returns a reference to this object. The value for type() and tableWidget() are not copied.

void QTableWidgetItem::read ( QDataStream in)
virtual

Reads the item from stream in.

See also
write()
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()
void QTableWidgetItem::setBackground ( const QBrush brush)
inline

Sets the item's background brush to the specified brush.

See also
background(), setForeground()
void QTableWidgetItem::setBackgroundColor ( const QColor color)
inlinedeprecated
void QTableWidgetItem::setCheckState ( Qt::CheckState  state)
inline

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

See also
checkState()
void QTableWidgetItem::setData ( int  role,
const QVariant value 
)
virtual

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

See also
data(), Qt::ItemDataRole
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()
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()
void QTableWidgetItem::setForeground ( const QBrush brush)
inline

Sets the item's foreground brush to the specified brush.

See also
foreground(), setBackground()
void QTableWidgetItem::setIcon ( const QIcon icon)
inline

Sets the item's icon to the icon specified.

See also
icon(), setText(), QAbstractItemView::iconSize
void QTableWidgetItem::setSelected ( bool  select)
inline

Sets the selected state of the item to select.

See also
isSelected()
void QTableWidgetItem::setSizeHint ( const QSize size)
inline

Sets the size hint for the table item to be size. If no size hint is set, the item delegate will compute the size hint based on the item data.

See also
sizeHint()
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()
void QTableWidgetItem::setText ( const QString text)
inline

Sets the item's text to the text specified.

See also
text(), setFont(), setForeground()
void QTableWidgetItem::setTextAlignment ( int  alignment)
inline

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

See also
textAlignment(), Qt::Alignment>
void QTableWidgetItem::setTextColor ( const QColor color)
inlinedeprecated
void QTableWidgetItem::setToolTip ( const QString toolTip)
inline

Sets the item's tooltip to the string specified by toolTip.

See also
toolTip(), setStatusTip(), setWhatsThis()
void QTableWidgetItem::setWhatsThis ( const QString whatsThis)
inline

Sets the item's "What's This?" help to the string specified by whatsThis.

See also
whatsThis(), setStatusTip(), setToolTip()
QSize QTableWidgetItem::sizeHint ( ) const
inline

Returns the size hint set for the table item.

See also
setSizeHint()
QString QTableWidgetItem::statusTip ( ) const
inline

Returns the item's status tip.

See also
setStatusTip()
QTableWidget * QTableWidgetItem::tableWidget ( ) const
inline

Returns the table widget that contains the item.

QString QTableWidgetItem::text ( ) const
inline

Returns the item's text.

See also
setText()
int QTableWidgetItem::textAlignment ( ) const
inline

Returns the text alignment for the item's text.

See also
setTextAlignment(), Qt::Alignment>
QColor QTableWidgetItem::textColor ( ) const
inlinedeprecated
QString QTableWidgetItem::toolTip ( ) const
inline

Returns the item's tooltip.

See also
setToolTip()
int QTableWidgetItem::type ( ) const
inline

Returns the type passed to the QTableWidgetItem constructor.

QString QTableWidgetItem::whatsThis ( ) const
inline

Returns the item's "What's This?" help.

See also
setWhatsThis()
void QTableWidgetItem::write ( QDataStream out) const
virtual

Writes the item to stream out.

See also
read()

Friends And Related Function Documentation

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

Writes the table widget item to stream out and returns a reference to the stream. This operator uses QTableWidgetItem::write().

Refer to Serializing Data Types for additional information.

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

Reads a table widget item from stream in into item and returns a reference to the stream. This operator uses QTableWidgetItem::read().

Refer to Serializing Data Types for additional information.