Home · All Classes · Modules

QTableWidgetItem Class Reference
[QtGui module]

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

Types

Methods

Special Methods


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

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


Type Documentation

QTableWidgetItem.ItemType

This enum describes the types that are used to describe table widget items.

Constant Value Description
QTableWidgetItem.Type 0 The default type for table widget items.
QTableWidgetItem.UserType 1000 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().


Method Documentation

QTableWidgetItem.__init__ (self, int type = QTableWidgetItem.Type)

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

See also type().

QTableWidgetItem.__init__ (self, QString text, int type = QTableWidgetItem.Type)

Constructs a table item with the given text.

See also type().

QTableWidgetItem.__init__ (self, QIcon icon, QString text, int type = QTableWidgetItem.Type)

Constructs a table item with the given icon and text.

See also type().

QTableWidgetItem.__init__ (self, QTableWidgetItem other)

Constructs a copy of other. Note that type() and tableWidget() are not copied.

This function is useful when reimplementing clone().

This function was introduced in Qt 4.1.

See also data() and flags().

QBrush QTableWidgetItem.background (self)

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

This function was introduced in Qt 4.2.

See also setBackground() and foreground().

QColor QTableWidgetItem.backgroundColor (self)

Qt.CheckState QTableWidgetItem.checkState (self)

Returns the checked state of the table item.

See also setCheckState() and flags().

QTableWidgetItem QTableWidgetItem.clone (self)

Creates a copy of the item.

int QTableWidgetItem.column (self)

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

This function was introduced in Qt 4.2.

See also row().

QVariant QTableWidgetItem.data (self, int role)

Returns the item's data for the given role.

See also setData().

Qt.ItemFlags QTableWidgetItem.flags (self)

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

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

See also setFont().

QBrush QTableWidgetItem.foreground (self)

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

This function was introduced in Qt 4.2.

See also setForeground() and background().

QIcon QTableWidgetItem.icon (self)

Returns the item's icon.

See also setIcon() and iconSize.

bool QTableWidgetItem.isSelected (self)

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

This function was introduced in Qt 4.2.

See also setSelected().

QTableWidgetItem.read (self, QDataStream in)

Reads the item from stream in.

See also write().

int QTableWidgetItem.row (self)

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

This function was introduced in Qt 4.2.

See also column().

QTableWidgetItem.setBackground (self, QBrush brush)

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

This function was introduced in Qt 4.2.

See also background() and setForeground().

QTableWidgetItem.setBackgroundColor (self, QColor color)

QTableWidgetItem.setCheckState (self, Qt.CheckState state)

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

See also checkState().

QTableWidgetItem.setData (self, int role, QVariant value)

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

See also Qt.ItemDataRole and data().

QTableWidgetItem.setFlags (self, Qt.ItemFlags aflags)

Sets the flags for the item to the given flags. These determine whether the item can be selected or modified.

See also flags().

QTableWidgetItem.setFont (self, QFont afont)

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

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

QTableWidgetItem.setForeground (self, QBrush brush)

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

This function was introduced in Qt 4.2.

See also foreground() and setBackground().

QTableWidgetItem.setIcon (self, QIcon aicon)

Sets the item's icon to the icon specified.

See also icon(), setText(), and iconSize.

QTableWidgetItem.setSelected (self, bool aselect)

Sets the selected state of the item to select.

This function was introduced in Qt 4.2.

See also isSelected().

QTableWidgetItem.setSizeHint (self, QSize size)

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.

This function was introduced in Qt 4.1.

See also sizeHint().

QTableWidgetItem.setStatusTip (self, QString astatusTip)

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(), and setWhatsThis().

QTableWidgetItem.setText (self, QString atext)

Sets the item's text to the text specified.

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

QTableWidgetItem.setTextAlignment (self, int alignment)

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

See also textAlignment() and Qt.Alignment.

QTableWidgetItem.setTextColor (self, QColor color)

QTableWidgetItem.setToolTip (self, QString atoolTip)

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

See also toolTip(), setStatusTip(), and setWhatsThis().

QTableWidgetItem.setWhatsThis (self, QString awhatsThis)

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

See also whatsThis(), setStatusTip(), and setToolTip().

QSize QTableWidgetItem.sizeHint (self)

Returns the size hint set for the table item.

This function was introduced in Qt 4.1.

See also setSizeHint().

QString QTableWidgetItem.statusTip (self)

Returns the item's status tip.

See also setStatusTip().

QTableWidget QTableWidgetItem.tableWidget (self)

Returns the table widget that contains the item.

QString QTableWidgetItem.text (self)

Returns the item's text.

See also setText().

int QTableWidgetItem.textAlignment (self)

Returns the text alignment for the item's text.

See also setTextAlignment() and Qt.Alignment.

QColor QTableWidgetItem.textColor (self)

QString QTableWidgetItem.toolTip (self)

Returns the item's tooltip.

See also setToolTip().

int QTableWidgetItem.type (self)

Returns the type passed to the QTableWidgetItem constructor.

QString QTableWidgetItem.whatsThis (self)

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

See also setWhatsThis().

QTableWidgetItem.write (self, QDataStream out)

Writes the item to stream out.

See also read().

bool QTableWidgetItem.__ge__ (self, QTableWidgetItem other)

bool QTableWidgetItem.__lt__ (self, QTableWidgetItem other)


PyQt 4.12.1 for X11Copyright © Riverbank Computing Ltd and The Qt Company 2015Qt 4.8.7