QTableWidgetItem 類

QTableWidgetItem 類提供項為用於 QTableWidget 類。 更多...

頭: #include <QTableWidgetItem>
qmake: QT += widgets

公共類型

enum ItemType { Type, UserType }

公共函數

QTableWidgetItem (const QTableWidgetItem & other )
QTableWidgetItem (const QIcon & icon , const QString & text , int type = Type)
QTableWidgetItem (const QString & text , int type = Type)
QTableWidgetItem (int type = Type)
QTableWidgetItem & operator= (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 )
void setTextAlignment (int 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
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 ().

成員函數文檔編製

QTableWidgetItem:: QTableWidgetItem (const QTableWidgetItem & other )

構造副本為 other 。注意, type () 和 tableWidget () 不拷貝。

此函數是有用的,當重實現 clone ().

該函數在 Qt 4.1 引入。

另請參閱 data () 和 flags ().

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 QString & text , int type = Type)

Constructs a table item with the given text .

另請參閱 type ().

QTableWidgetItem:: QTableWidgetItem ( int type = Type)

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

另請參閱 type ().

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

賦值 other 的數據和標誌到此項。注意 type () 和 tableWidget () 不拷貝。

此函數是有用的,當重實現 clone ().

另請參閱 data () 和 flags ().

[虛擬] QTableWidgetItem:: ~QTableWidgetItem ()

Destroys the table item.

QBrush QTableWidgetItem:: background () const

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

該函數在 Qt 4.2 引入。

另請參閱 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.

該函數在 Qt 4.2 引入。

另請參閱 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).

該函數在 Qt 4.2 引入。

另請參閱 setForeground () 和 background ().

QIcon QTableWidgetItem:: icon () const

返迴項圖標。

另請參閱 setIcon () 和 iconSize .

bool QTableWidgetItem:: isSelected () const

返迴 true 若項被選中,否則返迴 false .

該函數在 Qt 4.2 引入。

另請參閱 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.

該函數在 Qt 4.2 引入。

另請參閱 column ().

void QTableWidgetItem:: setBackground (const QBrush & brush )

Sets the item's background brush to the specified brush 。設置默認構造的筆刷將使視圖使用來自樣式的默認顔色。

該函數在 Qt 4.2 引入。

另請參閱 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 。設置默認構造的筆刷將使視圖使用來自樣式的默認顔色。

該函數在 Qt 4.2 引入。

另請參閱 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 .

該函數在 Qt 4.2 引入。

另請參閱 isSelected ().

void QTableWidgetItem:: setSizeHint (const QSize & size )

Sets the size hint for the table item to be size 。若未設置大小提示或 size 無效,項委托將基於項數據計算大小提示。

該函數在 Qt 4.1 引入。

另請參閱 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 ().

void QTableWidgetItem:: setTextAlignment ( int alignment )

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

另請參閱 textAlignment () 和 Qt::Alignment .

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.

該函數在 Qt 4.1 引入。

另請參閱 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.

另請參閱 setTextAlignment () 和 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.

相關非成員

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 數據類型 .