QTableWidgetItem 类

QTableWidgetItem 类提供项为用于 QTableWidget 类。 更多...

头: #include <QTableWidgetItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets

公共类型

enum ItemType { Type, UserType }

公共函数

QTableWidgetItem (int type = Type)
QTableWidgetItem (const QString & text , int type = Type)
QTableWidgetItem (const QIcon & icon , const QString & text , int type = Type)
QTableWidgetItem (const QTableWidgetItem & other )
virtual ~QTableWidgetItem ()
QBrush background () 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 void read (QDataStream & in )
int row () const
void setBackground (const QBrush & brush )
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 )
(从 6.4 起) void setTextAlignment (Qt::Alignment alignment )
void setToolTip (const QString & toolTip )
void setWhatsThis (const QString & whatsThis )
QSize sizeHint () const
QString statusTip () const
QTableWidget * tableWidget () const
QString text () const
int textAlignment () const
QString toolTip () const
int type () const
QString whatsThis () const
virtual void write (QDataStream & out ) const
virtual bool operator< (const QTableWidgetItem & other ) const
QTableWidgetItem & operator= (const QTableWidgetItem & other )
QDataStream & operator<< (QDataStream & out , const QTableWidgetItem & item )
QDataStream & operator>> (QDataStream & in , QTableWidgetItem & item )

详细描述

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 类。

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 () 函数。可以找到当前背景笔刷采用 background (). The text label for each item can be rendered with its own font and brush. These are specified with the setFont () 和 setForeground () 函数,和读取采用 font () 和 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 () 采用适当值 (见 Qt::ItemFlags )。可复选项可以被复选和取消复选采用 setCheckState () 函数。相应 checkState () 函数指示项目前是否被复选。

子类化

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 .

另请参阅 QTableWidget , 模型/视图编程 , QListWidgetItem ,和 QTreeWidgetItem .

成员类型文档编制

enum QTableWidgetItem:: ItemType

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

常量 描述
QTableWidgetItem::Type 0 The default type for table widget items.
QTableWidgetItem::UserType 1000 用于自定义类型的最小值。低于 UserType 的值由 Qt 预留。

可以定义新用户类型在 QTableWidgetItem 子类以确保自定义项被特殊对待。

另请参阅 type ().

成员函数文档编制

[explicit] QTableWidgetItem:: QTableWidgetItem ( int type = Type)

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

另请参阅 type ().

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

Constructs a table item with the given text .

另请参阅 type ().

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

Constructs a table item with the given icon and text .

另请参阅 type ().

QTableWidgetItem:: QTableWidgetItem (const QTableWidgetItem & other )

构造副本为 other 。注意, type () 和 tableWidget () 不拷贝。

此函数是有用的,当重实现 clone ().

另请参阅 data () 和 flags ().

[virtual noexcept] QTableWidgetItem:: ~QTableWidgetItem ()

Destroys the table item.

QBrush QTableWidgetItem:: background () const

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

另请参阅 setBackground () 和 foreground ().

Qt::CheckState QTableWidgetItem:: checkState () const

Returns the checked state of the table item.

另请参阅 setCheckState () 和 flags ().

[虚拟] QTableWidgetItem *QTableWidgetItem:: clone () const

Creates a copy of the item.

int QTableWidgetItem:: column () const

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

另请参阅 row ().

[虚拟] QVariant QTableWidgetItem:: data ( int role ) const

Returns the item's data for the given role .

另请参阅 setData ().

Qt::ItemFlags QTableWidgetItem:: flags () const

返回用于描述项的标志。这些确定项是否可以被复选、编辑及选择。

另请参阅 setFlags ().

QFont QTableWidgetItem:: font () const

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

另请参阅 setFont ().

QBrush QTableWidgetItem:: foreground () const

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

另请参阅 setForeground () 和 background ().

QIcon QTableWidgetItem:: icon () const

返回项图标。

另请参阅 setIcon () 和 iconSize .

bool QTableWidgetItem:: isSelected () const

返回 true 若项被选中,否则返回 false .

另请参阅 setSelected ().

[虚拟] void QTableWidgetItem:: read ( QDataStream & in )

读取项从流 in .

另请参阅 write ().

int QTableWidgetItem:: row () const

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

另请参阅 column ().

void QTableWidgetItem:: setBackground (const QBrush & brush )

Sets the item's background brush to the specified brush 。设置默认构造的笔刷将使视图使用来自样式的默认颜色。

另请参阅 background () 和 setForeground ().

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

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

另请参阅 checkState ().

[虚拟] void QTableWidgetItem:: setData ( int role , const QVariant & value )

Sets the item's data for the given role 到指定 value .

注意: 默认实现视 Qt::EditRole and Qt::DisplayRole 为引用相同数据。

另请参阅 Qt::ItemDataRole and data ().

void QTableWidgetItem:: setFlags ( Qt::ItemFlags flags )

将项的标志设为给定 flags . These determine whether the item can be selected or modified.

另请参阅 flags ().

void QTableWidgetItem:: setFont (const QFont & font )

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

另请参阅 font (), setText (),和 setForeground ().

void QTableWidgetItem:: setForeground (const QBrush & brush )

Sets the item's foreground brush to the specified brush 。设置默认构造的笔刷将使视图使用来自样式的默认颜色。

另请参阅 foreground () 和 setBackground ().

void QTableWidgetItem:: setIcon (const QIcon & icon )

Sets the item's icon to the icon 指定。

另请参阅 icon (), setText (),和 iconSize .

void QTableWidgetItem:: setSelected ( bool select )

将项的选定状态设为 select .

另请参阅 isSelected ().

void QTableWidgetItem:: setSizeHint (const QSize & size )

Sets the size hint for the table item to be size 。若未设置大小提示或 size 无效,项委托将基于项数据计算大小提示。

另请参阅 sizeHint ().

void QTableWidgetItem:: setStatusTip (const QString & statusTip )

Sets the status tip for the table item to the text specified by statusTip . QTableWidget 需要启用鼠标追踪,为使此特征能工作。

另请参阅 statusTip (), setToolTip (),和 setWhatsThis ().

void QTableWidgetItem:: setText (const QString & text )

Sets the item's text to the text 指定。

另请参阅 text (), setFont (),和 setForeground ().

[since 6.4] void QTableWidgetItem:: setTextAlignment ( Qt::Alignment alignment )

Sets the text alignment for the item's text to the alignment 指定。

该函数在 Qt 6.4 引入。

void QTableWidgetItem:: setToolTip (const QString & toolTip )

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

另请参阅 toolTip (), setStatusTip (),和 setWhatsThis ().

void QTableWidgetItem:: setWhatsThis (const QString & whatsThis )

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

另请参阅 whatsThis (), setStatusTip (),和 setToolTip ().

QSize QTableWidgetItem:: sizeHint () const

Returns the size hint set for the table item.

另请参阅 setSizeHint ().

QString QTableWidgetItem:: statusTip () const

Returns the item's status tip.

另请参阅 setStatusTip ().

QTableWidget *QTableWidgetItem:: tableWidget () const

Returns the table widget that contains the item.

QString QTableWidgetItem:: text () const

返回项的文本。

另请参阅 setText ().

int QTableWidgetItem:: textAlignment () const

Returns the text alignment for the item's text.

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

另请参阅 Qt::Alignment .

QString QTableWidgetItem:: toolTip () const

Returns the item's tooltip.

另请参阅 setToolTip ().

int QTableWidgetItem:: type () const

返回类型被传递给 QTableWidgetItem 构造函数。

QString QTableWidgetItem:: whatsThis () const

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

另请参阅 setWhatsThis ().

[虚拟] void QTableWidgetItem:: write ( QDataStream & out ) const

把项写入流 out .

另请参阅 read ().

[虚拟] bool QTableWidgetItem:: operator< (const QTableWidgetItem & other ) const

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

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

赋值 other 的数据和标志到此项。注意 type () 和 tableWidget () 不拷贝。

此函数是有用的,当重实现 clone ().

另请参阅 data () 和 flags ().

相关非成员

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

Writes the table widget item item 到流 out .

此操作符使用 QTableWidgetItem::write ().

另请参阅 序列化 Qt 数据类型 .

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

Reads a table widget item from stream in into item .

此操作符使用 QTableWidgetItem::read ().

另请参阅 序列化 Qt 数据类型 .