The QTreeWidgetItem 類提供項為用於 QTreeWidget 方便類。 更多...
| 頭: | #include <QTreeWidgetItem> |
| qmake: | QT += widgets |
| enum | ChildIndicatorPolicy { ShowIndicator, DontShowIndicator, DontShowIndicatorWhenChildless } |
| enum | ItemType { Type, UserType } |
| QTreeWidgetItem (int type = Type) | |
| QTreeWidgetItem (const QStringList & strings , int type = Type) | |
| QTreeWidgetItem (QTreeWidget * parent , int type = Type) | |
| QTreeWidgetItem (QTreeWidget * parent , const QStringList & strings , int type = Type) | |
| QTreeWidgetItem (QTreeWidget * parent , QTreeWidgetItem * preceding , int type = Type) | |
| QTreeWidgetItem (QTreeWidgetItem * parent , int type = Type) | |
| QTreeWidgetItem (QTreeWidgetItem * parent , const QStringList & strings , int type = Type) | |
| QTreeWidgetItem (QTreeWidgetItem * parent , QTreeWidgetItem * preceding , int type = Type) | |
| QTreeWidgetItem (const QTreeWidgetItem & other ) | |
| virtual | ~QTreeWidgetItem () |
| void | addChild (QTreeWidgetItem * child ) |
| void | addChildren (const QList<QTreeWidgetItem *> & children ) |
| QBrush | background (int column ) const |
| Qt::CheckState | checkState (int column ) const |
| QTreeWidgetItem * | child (int index ) const |
| int | childCount () const |
| QTreeWidgetItem::ChildIndicatorPolicy | childIndicatorPolicy () const |
| virtual QTreeWidgetItem * | clone () const |
| int | columnCount () const |
| virtual QVariant | data (int column , int role ) const |
| Qt::ItemFlags | flags () const |
| QFont | font (int column ) const |
| QBrush | foreground (int column ) const |
| QIcon | icon (int column ) const |
| int | indexOfChild (QTreeWidgetItem * child ) const |
| void | insertChild (int index , QTreeWidgetItem * child ) |
| void | insertChildren (int index , const QList<QTreeWidgetItem *> & children ) |
| bool | isDisabled () const |
| bool | isExpanded () const |
| bool | isFirstColumnSpanned () const |
| bool | isHidden () const |
| bool | isSelected () const |
| QTreeWidgetItem * | parent () const |
| virtual void | read (QDataStream & in ) |
| void | removeChild (QTreeWidgetItem * child ) |
| void | setBackground (int column , const QBrush & brush ) |
| void | setCheckState (int column , Qt::CheckState state ) |
| void | setChildIndicatorPolicy (QTreeWidgetItem::ChildIndicatorPolicy policy ) |
| virtual void | setData (int column , int role , const QVariant & value ) |
| void | setDisabled (bool disabled ) |
| void | setExpanded (bool expand ) |
| void | setFirstColumnSpanned (bool span ) |
| void | setFlags (Qt::ItemFlags flags ) |
| void | setFont (int column , const QFont & font ) |
| void | setForeground (int column , const QBrush & brush ) |
| void | setHidden (bool hide ) |
| void | setIcon (int column , const QIcon & icon ) |
| void | setSelected (bool select ) |
| void | setSizeHint (int column , const QSize & size ) |
| void | setStatusTip (int column , const QString & statusTip ) |
| void | setText (int column , const QString & text ) |
| void | setTextAlignment (int column , int alignment ) |
| void | setToolTip (int column , const QString & toolTip ) |
| void | setWhatsThis (int column , const QString & whatsThis ) |
| QSize | sizeHint (int column ) const |
| void | sortChildren (int column , Qt::SortOrder order ) |
| QString | statusTip (int column ) const |
| QTreeWidgetItem * | takeChild (int index ) |
| QList<QTreeWidgetItem *> | takeChildren () |
| QString | text (int column ) const |
| int | textAlignment (int column ) const |
| QString | toolTip (int column ) const |
| QTreeWidget * | treeWidget () const |
| int | type () const |
| QString | whatsThis (int column ) const |
| virtual void | write (QDataStream & out ) const |
| virtual bool | operator< (const QTreeWidgetItem & other ) const |
| QTreeWidgetItem & | operator= (const QTreeWidgetItem & other ) |
| void | emitDataChanged () |
| QDataStream & | operator<< (QDataStream & out , const QTreeWidgetItem & item ) |
| QDataStream & | operator>> (QDataStream & in , QTreeWidgetItem & item ) |
The QTreeWidgetItem 類提供項為用於 QTreeWidget 方便類。
樹 Widget 項用於保持樹小部件的信息行。行通常包含幾列數據,每列數據可以包含文本標簽和圖標。
The QTreeWidgetItem class is a convenience class that replaces the QListViewItem class in Qt 3. It provides an item for use with the QTreeWidget 類。
項構造通常采用的父級要麼是 QTreeWidget (for top-level items) or a QTreeWidgetItem (for items on lower levels of the tree). For example, the following code constructs a top-level item to represent cities of the world, and adds a entry for Oslo as a child item:
QTreeWidgetItem *cities = new QTreeWidgetItem(treeWidget);
cities->setText(0, tr("Cities"));
QTreeWidgetItem *osloItem = new QTreeWidgetItem(cities);
osloItem->setText(0, tr("Oslo"));
osloItem->setText(1, tr("Yes"));
通過指定它們所跟隨的項可以按特定次序添加項,當構造它們時:
QTreeWidgetItem *planets = new QTreeWidgetItem(treeWidget, cities);
planets->setText(0, tr("Planets"));
項中每列可以擁有自己的背景筆刷,設置采用 setBackground () 函數。可以找到當前背景筆刷采用 background ()。每列的文本標簽可以采用自己的字體和筆刷渲染。指定這些采用 setFont () 和 setForeground () 函數,和讀取采用 font () 和 foreground ().
頂層項和樹中較低級項的主要差異是頂層項沒有 parent ()。此信息可用於區分項之間的差異,且有助於瞭解何時插入和從樹中移除項。可以移除項的子級采用 takeChild () 和插入在子級列錶中的給定索引處采用 insertChild () 函數。
默認情況下,項是啓用的、可選擇的、可復選的及可以是拖放操作的來源。可以改變每項的標誌通過調用 setFlags () 采用適當值 (見 Qt::ItemFlags )。可復選項可以被復選和取消復選采用 setCheckState () 函數。相應 checkState () 函數指示項目前是否被復選。
當子類化 QTreeWidgetItem 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 .
另請參閱 QTreeWidget , QTreeWidgetItemIterator , 模型/視圖編程 , QListWidgetItem ,和 QTableWidgetItem .
| 常量 | 值 | 描述 |
|---|---|---|
QTreeWidgetItem::ShowIndicator
|
0
|
將展示此項的展開和摺疊控件,即使沒有子級。 |
QTreeWidgetItem::DontShowIndicator
|
1
|
從不展示用於展開和摺疊的控件,即使有子級。若節點被強製打開,用戶將無法展開或摺疊項。 |
QTreeWidgetItem::DontShowIndicatorWhenChildless
|
2
|
將展示用於展開和摺疊的控件,若項包含子級。 |
該枚舉在 Qt 4.3 引入或被修改。
此枚舉描述用於描述樹 Widget 項的類型。
| 常量 | 值 | 描述 |
|---|---|---|
QTreeWidgetItem::Type
|
0
|
用於樹 Widget 項的默認類型。 |
QTreeWidgetItem::UserType
|
1000
|
用於自定義類型的最小值。低於 UserType 的值由 Qt 預留。 |
可以定義新用戶類型在 QTreeWidgetItem 子類以確保自定義項得到特殊處理;例如,當排序項時。
另請參閱 type ().
構造樹 Widget 項采用指定 type 。項必須被插入樹 Widget。
另請參閱 type ().
構造樹 Widget 項采用指定 type 。項必須被插入樹小部件。給定列錶的 strings 將被設置作為項中每列的項文本。
另請參閱 type ().
構造樹 Widget 項采用指定 type 並將其追加到項在給定 parent .
另請參閱 type ().
構造樹 Widget 項采用指定 type 並將其追加到項在給定 parent 。給定列錶 strings 將被設置作為項中每列的項文本。
另請參閱 type ().
構造樹 Widget 項采用指定 type 並將其插入給定 parent 後於 preceding 項。
另請參閱 type ().
構造樹 Widget 項並將其追加到給定 parent .
另請參閱 type ().
構造樹 Widget 項並將其追加到給定 parent 。給定列錶 strings 將被設置作為項中每列的項文本。
另請參閱 type ().
構造樹 Widget 項采用指定 type 其被插入 parent 後於 preceding 子級項。
另請參閱 type ().
構造副本為 other 。注意, type () 和 treeWidget () 不拷貝。
此函數是有用的,當重實現 clone ().
該函數在 Qt 4.1 引入。
[虛擬]
QTreeWidgetItem::
~QTreeWidgetItem
()
銷毀此樹 Widget 項。
項將被移除從 QTreeWidget 若它已被添加。這使之可安全地隨時刪除項。
追加 child 項到子級列錶。
另請參閱 insertChild () 和 takeChild ().
追加給定列錶 children 到項。
該函數在 Qt 4.1 引入。
另請參閱 insertChildren () 和 takeChildren ().
返迴用於渲染背景的筆刷為指定 column .
該函數在 Qt 4.2 引入。
另請參閱 setBackground () 和 foreground ().
返迴標簽的校驗狀態在給定 column .
另請參閱 setCheckState () 和 Qt::CheckState .
返迴項位於給定 index 在項的子級列錶中。
另請參閱 parent ().
返迴子級項數。
返迴項指示符策略。此策略決定何時展示樹分支展開/摺疊指示符。
另請參閱 setChildIndicatorPolicy ().
[虛擬]
QTreeWidgetItem
*QTreeWidgetItem::
clone
() const
創建項及其子級的深拷貝。
返迴項中的列數。
[虛擬]
QVariant
QTreeWidgetItem::
data
(
int
column
,
int
role
) const
返迴值對於項的 column and role .
另請參閱 setData ().
[protected]
void
QTreeWidgetItem::
emitDataChanged
()
促使關聯此項的模型發射 dataChanged () 信號對於此項。
通常隻需調用此函數若有子類化 QTreeWidgetItem 並重實現 data () 和/或 setData ().
該函數在 Qt 4.5 引入。
另請參閱 setData ().
返迴用於描述項的標誌。這些確定項是否可以被復選、編輯及選擇。
標誌的默認值為 Qt::ItemIsSelectable | Qt::ItemIsUserCheckable | Qt::ItemIsEnabled | Qt::ItemIsDragEnabled | Qt::ItemIsDropEnabled .
另請參閱 setFlags ().
返迴用於渲染文本的字體在指定 column .
另請參閱 setFont ().
返迴用於渲染前景 (如:文本) 的筆刷為指定 column .
該函數在 Qt 4.2 引入。
另請參閱 setForeground () 和 background ().
返迴的圖標顯示在指定 column .
返迴索引為給定 child 在項的子級列錶中。
插入 child 項在 index 在子級列錶。
不會再次插入子級,若已插入在某些地方。
插入給定列錶為 children 進項子級列錶在 index .
已插入其它地方的子級不會被插入。
該函數在 Qt 4.1 引入。
返迴
true
若項被禁用;否則返迴
false
.
該函數在 Qt 4.3 引入。
另請參閱 setFlags ().
返迴
true
若項被展開,否則返迴
false
.
該函數在 Qt 4.2 引入。
另請參閱 setExpanded ().
返迴
true
若項跨行中所有列;否則返迴
false
.
該函數在 Qt 4.3 引入。
另請參閱 setFirstColumnSpanned ().
返迴
true
若項被隱藏,否則返迴
false
.
該函數在 Qt 4.2 引入。
另請參閱 setHidden ().
返迴
true
若項被選中,否則返迴
false
.
該函數在 Qt 4.2 引入。
另請參閱 setSelected ().
返迴項的父級。
另請參閱 child ().
[虛擬]
void
QTreeWidgetItem::
read
(
QDataStream
&
in
)
讀取項從流 in 。這隻將數據讀取到單項。
另請參閱 write ().
刪除給定項指示通過 child 。移除項不會被刪除。
設置標簽背景筆刷在給定 column 到指定 brush .
該函數在 Qt 4.2 引入。
另請參閱 background () 和 setForeground ().
設置項在給定 column 復選狀態為 state .
另請參閱 checkState ().
設置項指示器 policy . This policy decides when the tree branch expand/collapse indicator is shown. The default value is ShowForChildren.
另請參閱 childIndicatorPolicy ().
[虛擬]
void
QTreeWidgetItem::
setData
(
int
column
,
int
role
, const
QVariant
&
value
)
設置值對於項的 column and role 到給定 value .
The role 描述數據類型指定通過 value ,和定義通過 Qt::ItemDataRole 枚舉。
注意: 默認實現視 Qt::EditRole and Qt::DisplayRole 為引用相同數據。
另請參閱 data ().
禁用項若 disabled 為 true;否則啓用項。
該函數在 Qt 4.3 引入。
另請參閱 isDisabled () 和 setFlags ().
展開項若 expand 為 true,否則摺疊項。
警告: The QTreeWidgetItem 必須被添加到 QTreeWidget 在調用此函數之前。
該函數在 Qt 4.2 引入。
另請參閱 isExpanded ().
把第 1 區間設為跨所有列若 span 為 true;否則展示所有項區間。
該函數在 Qt 4.3 引入。
另請參閱 isFirstColumnSpanned ().
將項的標誌設為給定 flags 。這些確定是否可以選擇或修改項。這經常用於禁用項。
另請參閱 flags ().
設置用於顯示文本的字體在給定 column 到給定 font .
另請參閱 font (), setText (),和 setForeground ().
設置標簽的前景筆刷在給定 column 到指定 brush .
該函數在 Qt 4.2 引入。
另請參閱 foreground () 和 setBackground ().
隱藏項若 hide 為 True,否則展示項。
注意:
調用此函數不起作用,若項目前不在視圖中。尤其,調用
setHidden(true)
在項,然後纔將它添加到視圖會導緻項可見。
該函數在 Qt 4.2 引入。
另請參閱 isHidden ().
設置要顯示的圖標在給定 column to icon .
另請參閱 icon (), setText (),和 iconSize .
將項的選定狀態設為 select .
該函數在 Qt 4.2 引入。
另請參閱 isSelected ().
設置樹項大小提示在給定 column 到 size 。若未設置大小提示,項委托將基於項數據計算大小提示。
該函數在 Qt 4.1 引入。
另請參閱 sizeHint ().
設置狀態提示為給定 column 到給定 statusTip . QTreeWidget 需要啓用鼠標追蹤,為使此特徵能工作。
另請參閱 statusTip (), setToolTip (),和 setWhatsThis ().
設置要顯示的文本在給定 column 到給定 text .
另請參閱 text (), setFont (),和 setForeground ().
設置標簽的文本對齊方式在給定 column 到 alignment 指定 (見 Qt::AlignmentFlag ).
另請參閱 textAlignment ().
設置工具提示為給定 column to toolTip .
另請參閱 toolTip (), setStatusTip (),和 setWhatsThis ().
設置 What's This? 幫助為給定 column to whatsThis .
另請參閱 whatsThis (), setStatusTip (),和 setToolTip ().
返迴為樹項設置的大小提示在給定 column (見 QSize ).
該函數在 Qt 4.1 引入。
另請參閱 setSizeHint ().
排序項的子級使用給定 order ,通過值在給定 column .
注意: 此函數什麼都不做,若項不關聯 QTreeWidget .
該函數在 Qt 4.2 引入。
返迴狀態提示內容為給定 column .
另請參閱 setStatusTip ().
移除項在 index 並返迴它,否則返迴 0。
移除子級列錶並返迴它,否則返迴空列錶。
該函數在 Qt 4.1 引入。
返迴文本在指定 column .
另請參閱 setText ().
返迴標簽的文本對齊方式在給定 column (見 Qt::AlignmentFlag ).
另請參閱 setTextAlignment ().
返迴工具提示為給定 column .
另請參閱 setToolTip ().
返迴包含項的樹 Widget。
返迴類型被傳遞給 QTreeWidgetItem 構造函數。
返迴 What's This? 幫助內容為給定 column .
另請參閱 setWhatsThis ().
[虛擬]
void
QTreeWidgetItem::
write
(
QDataStream
&
out
) const
把項寫入流 out 。這僅從一單項寫入數據。
另請參閱 read ().
[虛擬]
bool
QTreeWidgetItem::
operator<
(const
QTreeWidgetItem
&
other
) const
返迴
true
若項文本小於文本在
other
項,否則返迴
false
.
賦值 other 的數據和標誌到此項。注意 type () 和 treeWidget () 不拷貝。
此函數是有用的,當重實現 clone ().
寫入樹 Widget 項 item 到流 out .
此操作符使用 QTreeWidgetItem::write ().
另請參閱 序列化 Qt 數據類型 .
讀取樹 Widget 項從流 in into item .
此操作符使用 QTreeWidgetItem::read ().
另請參閱 序列化 Qt 數據類型 .