The QTableWidgetItem 類提供項為用於 QTableWidget 類。 更多...
| 頭: | #include <QTableWidgetItem> |
| 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 ) |
| 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 |
| QTableWidgetItem & | operator= (const QTableWidgetItem & other ) |
| QDataStream & | operator<< (QDataStream & out , const QTableWidgetItem & item ) |
| QDataStream & | operator>> (QDataStream & in , QTableWidgetItem & item ) |
The QTableWidgetItem 類提供項為用於 QTableWidget 類。
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 () 函數指示項目前是否被復選。
當子類化 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 .
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 ().
Constructs a table item of the specified type that does not belong to any table.
另請參閱 type ().
Constructs a table item with the given text .
另請參閱 type ().
Constructs a table item with the given icon and text .
另請參閱 type ().
構造副本為 other 。注意, type () 和 tableWidget () 不拷貝。
此函數是有用的,當重實現 clone ().
該函數在 Qt 4.1 引入。
[虛擬]
QTableWidgetItem::
~QTableWidgetItem
()
Destroys the table item.
Returns the brush used to render the item's background.
該函數在 Qt 4.2 引入。
另請參閱 setBackground () 和 foreground ().
Returns the checked state of the table item.
另請參閱 setCheckState () 和 flags ().
[虛擬]
QTableWidgetItem
*QTableWidgetItem::
clone
() const
Creates a copy of the item.
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 ().
返迴用於描述項的標誌。這些確定項是否可以被復選、編輯及選擇。
另請參閱 setFlags ().
Returns the font used to render the item's text.
另請參閱 setFont ().
Returns the brush used to render the item's foreground (e.g. text).
該函數在 Qt 4.2 引入。
另請參閱 setForeground () 和 background ().
返迴項圖標。
返迴
true
若項被選中,否則返迴
false
.
該函數在 Qt 4.2 引入。
另請參閱 setSelected ().
[虛擬]
void
QTableWidgetItem::
read
(
QDataStream
&
in
)
讀取項從流 in .
另請參閱 write ().
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 ().
Sets the item's background brush to the specified brush .
該函數在 Qt 4.2 引入。
另請參閱 background () 和 setForeground ().
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 ().
將項的標誌設為給定 flags . These determine whether the item can be selected or modified.
另請參閱 flags ().
Sets the font used to display the item's text to the given font .
另請參閱 font (), setText (),和 setForeground ().
Sets the item's foreground brush to the specified brush .
該函數在 Qt 4.2 引入。
另請參閱 foreground () 和 setBackground ().
Sets the item's icon to the icon 指定。
另請參閱 icon (), setText (),和 iconSize .
將項的選定狀態設為 select .
該函數在 Qt 4.2 引入。
另請參閱 isSelected ().
Sets the size hint for the table item to be size 。若未設置大小提示,項委托將基於項數據計算大小提示。
該函數在 Qt 4.1 引入。
另請參閱 sizeHint ().
Sets the status tip for the table item to the text specified by statusTip . QTableWidget 需要啓用鼠標追蹤,為使此特徵能工作。
另請參閱 statusTip (), setToolTip (),和 setWhatsThis ().
Sets the item's text to the text 指定。
另請參閱 text (), setFont (),和 setForeground ().
Sets the text alignment for the item's text to the alignment 指定。
另請參閱 textAlignment () 和 Qt::Alignment .
Sets the item's tooltip to the string specified by toolTip .
另請參閱 toolTip (), setStatusTip (),和 setWhatsThis ().
Sets the item's "What's This?" help to the string specified by whatsThis .
另請參閱 whatsThis (), setStatusTip (),和 setToolTip ().
Returns the size hint set for the table item.
該函數在 Qt 4.1 引入。
另請參閱 setSizeHint ().
Returns the item's status tip.
另請參閱 setStatusTip ().
Returns the table widget that contains the item.
返迴項的文本。
另請參閱 setText ().
Returns the text alignment for the item's text.
另請參閱 setTextAlignment () 和 Qt::Alignment .
Returns the item's tooltip.
另請參閱 setToolTip ().
返迴類型被傳遞給 QTableWidgetItem 構造函數。
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.
賦值 other 的數據和標誌到此項。注意 type () 和 tableWidget () 不拷貝。
此函數是有用的,當重實現 clone ().
Writes the table widget item item 到流 out .
此操作符使用 QTableWidgetItem::write ().
另請參閱 序列化 Qt 數據類型 .
Reads a table widget item from stream in into item .
此操作符使用 QTableWidgetItem::read ().
另請參閱 序列化 Qt 數據類型 .