QTableWidgetItem

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

Inheritance diagram of PySide2.QtWidgets.QTableWidgetItem

Synopsis

Functions

Virtual functions

Detailed Description

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

class PySide2.QtWidgets.QTableWidgetItem(icon, text[, type=Type])

PySide2.QtWidgets.QTableWidgetItem(text[, type=Type])

PySide2.QtWidgets.QTableWidgetItem(other)

PySide2.QtWidgets.QTableWidgetItem([type=Type])

param type:

int

param icon:

PySide2.QtGui.QIcon

param other:

PySide2.QtWidgets.QTableWidgetItem

param text:

str

Constructs a table item with the given icon and text .

See also

type()

Constructs a table item with the given text .

See also

type()

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

See also

type()

PySide2.QtWidgets.QTableWidgetItem.ItemType

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

Constant

Description

QTableWidgetItem.Type

The default type for table widget items.

QTableWidgetItem.UserType

The minimum value for custom types. Values below are reserved by Qt.

You can define new user types in QTableWidgetItem subclasses to ensure that custom items are treated specially.

See also

type()

PySide2.QtWidgets.QTableWidgetItem.background()
Return type:

PySide2.QtGui.QBrush

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

PySide2.QtWidgets.QTableWidgetItem.backgroundColor()
Return type:

PySide2.QtGui.QColor

Note

This function is deprecated.

This function is deprecated. Use background() instead.

PySide2.QtWidgets.QTableWidgetItem.checkState()
Return type:

CheckState

Returns the checked state of the table item.

PySide2.QtWidgets.QTableWidgetItem.clone()
Return type:

PySide2.QtWidgets.QTableWidgetItem

Creates a copy of the item.

PySide2.QtWidgets.QTableWidgetItem.column()
Return type:

int

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

PySide2.QtWidgets.QTableWidgetItem.data(role)
Parameters:

role – int

Return type:

object

Returns the item’s data for the given role .

See also

setData()

PySide2.QtWidgets.QTableWidgetItem.flags()
Return type:

ItemFlags

Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.

See also

setFlags()

PySide2.QtWidgets.QTableWidgetItem.font()
Return type:

PySide2.QtGui.QFont

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

See also

setFont()

PySide2.QtWidgets.QTableWidgetItem.foreground()
Return type:

PySide2.QtGui.QBrush

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

PySide2.QtWidgets.QTableWidgetItem.icon()
Return type:

PySide2.QtGui.QIcon

Returns the item’s icon.

See also

setIcon() iconSize

PySide2.QtWidgets.QTableWidgetItem.isSelected()
Return type:

bool

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

See also

setSelected()

PySide2.QtWidgets.QTableWidgetItem.__lt__(other)
Parameters:

otherPySide2.QtWidgets.QTableWidgetItem

Return type:

bool

PySide2.QtWidgets.QTableWidgetItem.read(in)
Parameters:

inPySide2.QtCore.QDataStream

Reads the item from stream in .

See also

write()

PySide2.QtWidgets.QTableWidgetItem.row()
Return type:

int

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

PySide2.QtWidgets.QTableWidgetItem.setBackground(brush)
Parameters:

brushPySide2.QtGui.QBrush

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.

PySide2.QtWidgets.QTableWidgetItem.setBackgroundColor(color)
Parameters:

colorPySide2.QtGui.QColor

Note

This function is deprecated.

This function is deprecated. Use setBackground() instead.

PySide2.QtWidgets.QTableWidgetItem.setCheckState(state)
Parameters:

stateCheckState

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

See also

checkState()

PySide2.QtWidgets.QTableWidgetItem.setData(role, value)
Parameters:
  • role – int

  • value – object

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

Note

The default implementation treats EditRole and DisplayRole as referring to the same data.

See also

ItemDataRole data()

PySide2.QtWidgets.QTableWidgetItem.setFlags(flags)
Parameters:

flagsItemFlags

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

See also

flags()

PySide2.QtWidgets.QTableWidgetItem.setFont(font)
Parameters:

fontPySide2.QtGui.QFont

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

PySide2.QtWidgets.QTableWidgetItem.setForeground(brush)
Parameters:

brushPySide2.QtGui.QBrush

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.

PySide2.QtWidgets.QTableWidgetItem.setIcon(icon)
Parameters:

iconPySide2.QtGui.QIcon

Sets the item’s icon to the icon specified.

PySide2.QtWidgets.QTableWidgetItem.setSelected(select)
Parameters:

select – bool

Sets the selected state of the item to select .

See also

isSelected()

PySide2.QtWidgets.QTableWidgetItem.setSizeHint(size)
Parameters:

sizePySide2.QtCore.QSize

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.

See also

sizeHint()

PySide2.QtWidgets.QTableWidgetItem.setStatusTip(statusTip)
Parameters:

statusTip – str

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.

PySide2.QtWidgets.QTableWidgetItem.setText(text)
Parameters:

text – str

Sets the item’s text to the text specified.

PySide2.QtWidgets.QTableWidgetItem.setTextAlignment(alignment)
Parameters:

alignment – int

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

See also

textAlignment() Alignment

PySide2.QtWidgets.QTableWidgetItem.setTextColor(color)
Parameters:

colorPySide2.QtGui.QColor

Note

This function is deprecated.

This function is deprecated. Use setForeground() instead.

See also

textColor()

PySide2.QtWidgets.QTableWidgetItem.setToolTip(toolTip)
Parameters:

toolTip – str

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

PySide2.QtWidgets.QTableWidgetItem.setWhatsThis(whatsThis)
Parameters:

whatsThis – str

Sets the item’s “What’s This?” help to the string specified by whatsThis .

PySide2.QtWidgets.QTableWidgetItem.sizeHint()
Return type:

PySide2.QtCore.QSize

Returns the size hint set for the table item.

See also

setSizeHint()

PySide2.QtWidgets.QTableWidgetItem.statusTip()
Return type:

str

Returns the item’s status tip.

See also

setStatusTip()

PySide2.QtWidgets.QTableWidgetItem.tableWidget()
Return type:

PySide2.QtWidgets.QTableWidget

Returns the table widget that contains the item.

PySide2.QtWidgets.QTableWidgetItem.text()
Return type:

str

Returns the item’s text.

See also

setText()

PySide2.QtWidgets.QTableWidgetItem.textAlignment()
Return type:

int

Returns the text alignment for the item’s text.

See also

setTextAlignment() Alignment

PySide2.QtWidgets.QTableWidgetItem.textColor()
Return type:

PySide2.QtGui.QColor

Note

This function is deprecated.

This function is deprecated. Use foreground() instead.

See also

setTextColor()

PySide2.QtWidgets.QTableWidgetItem.toolTip()
Return type:

str

Returns the item’s tooltip.

See also

setToolTip()

PySide2.QtWidgets.QTableWidgetItem.type()
Return type:

int

Returns the type passed to the QTableWidgetItem constructor.

PySide2.QtWidgets.QTableWidgetItem.whatsThis()
Return type:

str

Returns the item’s “What’s This?” help.

See also

setWhatsThis()

PySide2.QtWidgets.QTableWidgetItem.write(out)
Parameters:

outPySide2.QtCore.QDataStream

Writes the item to stream out .

See also

read()