- class QTableWidgetItem¶
The
QTableWidgetItem
class provides an item for use with theQTableWidget
class. More…Synopsis¶
Methods¶
def
__init__()
def
background()
def
checkState()
def
column()
def
flags()
def
font()
def
foreground()
def
icon()
def
isSelected()
def
row()
def
setBackground()
def
setCheckState()
def
setFlags()
def
setFont()
def
setForeground()
def
setIcon()
def
setSelected()
def
setSizeHint()
def
setStatusTip()
def
setText()
def
setToolTip()
def
setWhatsThis()
def
sizeHint()
def
statusTip()
def
tableWidget()
def
text()
def
textAlignment()
def
toolTip()
def
type()
def
whatsThis()
Virtual methods¶
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
Detailed Description¶
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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 theQTableItem
class in Qt 3. It provides an item for use with theQTableWidget
class.Top-level items are constructed without a parent then inserted at the position specified by a pair of row and column numbers:
newItem = 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 withbackground()
. The text label for each item can be rendered with its own font and brush. These are specified with thesetFont()
andsetForeground()
functions, and read withfont()
andforeground()
.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 thesetCheckState()
function. The correspondingcheckState()
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 thanUserType
.- class ItemType¶
(inherits
enum.IntEnum
) 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 UserType are reserved by Qt.
You can define new user types in
QTableWidgetItem
subclasses to ensure that custom items are treated specially.See also
- __init__(other)¶
- Parameters:
other –
QTableWidgetItem
Constructs a copy of
other
. Note thattype()
andtableWidget()
are not copied.This function is useful when reimplementing
clone()
.- __init__([type=QTableWidgetItem.ItemType.Type])
- Parameters:
type – int
Constructs a table item of the specified
type
that does not belong to any table.See also
- __init__(text[, type=QTableWidgetItem.ItemType.Type])
- Parameters:
text – str
type – int
Constructs a table item with the given
text
.See also
- __init__(icon, text[, type=QTableWidgetItem.ItemType.Type])
- Parameters:
icon –
QIcon
text – str
type – int
Constructs a table item with the given
icon
andtext
.See also
Returns the brush used to render the item’s background.
See also
- checkState()¶
- Return type:
Returns the checked state of the table item.
See also
- clone()¶
- Return type:
Creates a copy of the item.
- 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
- data(role)¶
- Parameters:
role – int
- Return type:
object
Returns the item’s data for the given
role
.See also
Returns the flags used to describe the item. These determine whether the item can be checked, edited, and selected.
See also
Returns the font used to render the item’s text.
See also
Returns the brush used to render the item’s foreground (e.g. text).
See also
Returns the item’s icon.
- isSelected()¶
- Return type:
bool
Returns
true
if the item is selected, otherwise returnsfalse
.See also
- __lt__(other)¶
- Parameters:
other –
QTableWidgetItem
- Return type:
bool
Returns
true
if the item is less than theother
item; otherwise returns false.- read(in)¶
- Parameters:
in –
QDataStream
Reads the item from stream
in
.See also
- 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
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
- setCheckState(state)¶
- Parameters:
state –
CheckState
Sets the check state of the table item to be
state
.See also
- setData(role, value)¶
- Parameters:
role – int
value – object
Sets the item’s data for the given
role
to the specifiedvalue
.Note
The default implementation treats Qt::EditRole and Qt::DisplayRole as referring to the same data.
See also
Sets the flags for the item to the given
flags
. These determine whether the item can be selected or modified.See also
Sets the font used to display the item’s text to the given
font
.See also
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
Sets the item’s icon to the
icon
specified.- setSelected(select)¶
- Parameters:
select – bool
Sets the selected state of the item to
select
.See also
Sets the size hint for the table item to be
size
. If no size hint is set orsize
is invalid, the item delegate will compute the size hint based on the item data.See also
- 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.See also
- setText(text)¶
- Parameters:
text – str
Sets the item’s text to the
text
specified.See also
- setTextAlignment(alignment)¶
- Parameters:
alignment – Combination of
AlignmentFlag
Sets the text alignment for the item’s text to the
alignment
specified.See also
- setTextAlignment(alignment)
- Parameters:
alignment –
AlignmentFlag
- setTextAlignment(alignment)
- Parameters:
alignment – int
Note
This function is deprecated.
Use the overload that takes a Qt::Alignment argument.
Sets the text alignment for the item’s text to the
alignment
specified.See also
Alignment
- setToolTip(toolTip)¶
- Parameters:
toolTip – str
Sets the item’s tooltip to the string specified by
toolTip
.See also
- setWhatsThis(whatsThis)¶
- Parameters:
whatsThis – str
Sets the item’s “What’s This?” help to the string specified by
whatsThis
.See also
Returns the size hint set for the table item.
See also
- statusTip()¶
- Return type:
str
Returns the item’s status tip.
See also
- tableWidget()¶
- Return type:
Returns the table widget that contains the item.
- text()¶
- Return type:
str
Returns the item’s text.
See also
- textAlignment()¶
- Return type:
int
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
setTextAlignment()
Alignment
- toolTip()¶
- Return type:
str
Returns the item’s tooltip.
See also
- type()¶
- Return type:
int
Returns the type passed to the
QTableWidgetItem
constructor.- whatsThis()¶
- Return type:
str
Returns the item’s “What’s This?” help.
See also
- write(out)¶
- Parameters:
out –
QDataStream
Writes the item to stream
out
.See also