QTreeWidgetItemIterator 类

QTreeWidgetItemIterator 类提供手段以遍历项在 QTreeWidget 实例。 更多...

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

公共类型

enum IteratorFlag { All, Hidden, NotHidden, Selected, Unselected, …, UserFlag }
flags IteratorFlags

公共函数

QTreeWidgetItemIterator (QTreeWidget * widget , QTreeWidgetItemIterator::IteratorFlags flags = All)
QTreeWidgetItemIterator (QTreeWidgetItem * item , QTreeWidgetItemIterator::IteratorFlags flags = All)
QTreeWidgetItemIterator (const QTreeWidgetItemIterator & it )
~QTreeWidgetItemIterator ()
QTreeWidgetItem * operator* () const
QTreeWidgetItemIterator & operator++ ()
const QTreeWidgetItemIterator operator++ (int)
QTreeWidgetItemIterator & operator+= (int n )
QTreeWidgetItemIterator & operator-- ()
const QTreeWidgetItemIterator operator-- (int)
QTreeWidgetItemIterator & operator-= (int n )
QTreeWidgetItemIterator & operator= (const QTreeWidgetItemIterator & it )

详细描述

迭代器将按预定次序的遍历顺序走查项,从而拜访父级节点 before 它继续到子级节点。

例如,以下代码范例中的每一树项,对照用户指定的搜索字符串校验首列文本:

    QTreeWidgetItemIterator it(treeWidget);
    while (*it) {
        if ((*it)->text(0) == itemText)
            (*it)->setSelected(true);
        ++it;
    }
					

过滤出某些类型的节点也是可能的,通过传递一些 flags 到 QTreeWidgetItemIterator 构造函数。

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

成员类型文档编制

enum QTreeWidgetItemIterator:: IteratorFlag
flags QTreeWidgetItemIterator:: IteratorFlags

这些标志可以传递给 QTreeWidgetItemIterator 构造函数 (OR 在一起若使用一个以上),以便迭代器将仅迭代匹配给定标志的项。

常量
QTreeWidgetItemIterator::All 0x00000000
QTreeWidgetItemIterator::Hidden 0x00000001
QTreeWidgetItemIterator::NotHidden 0x00000002
QTreeWidgetItemIterator::Selected 0x00000004
QTreeWidgetItemIterator::Unselected 0x00000008
QTreeWidgetItemIterator::Selectable 0x00000010
QTreeWidgetItemIterator::NotSelectable 0x00000020
QTreeWidgetItemIterator::DragEnabled 0x00000040
QTreeWidgetItemIterator::DragDisabled 0x00000080
QTreeWidgetItemIterator::DropEnabled 0x00000100
QTreeWidgetItemIterator::DropDisabled 0x00000200
QTreeWidgetItemIterator::HasChildren 0x00000400
QTreeWidgetItemIterator::NoChildren 0x00000800
QTreeWidgetItemIterator::Checked 0x00001000
QTreeWidgetItemIterator::NotChecked 0x00002000
QTreeWidgetItemIterator::Enabled 0x00004000
QTreeWidgetItemIterator::Disabled 0x00008000
QTreeWidgetItemIterator::Editable 0x00010000
QTreeWidgetItemIterator::NotEditable 0x00020000
QTreeWidgetItemIterator::UserFlag 0x01000000

IteratorFlags 类型是 typedef 对于 QFlags <IteratorFlag>。它存储 IteratorFlag 值的 OR 组合。

成员函数文档编制

[explicit] QTreeWidgetItemIterator:: QTreeWidgetItemIterator ( QTreeWidget * widget , QTreeWidgetItemIterator::IteratorFlags flags = All)

构造迭代器为给定 widget 使用指定 flags 以确定在迭代期间找到哪些项。迭代器被设为指向 Widget 包含的第一顶层项,或下一匹配项若顶层项不匹配标志。

另请参阅 QTreeWidgetItemIterator::IteratorFlag .

[explicit] QTreeWidgetItemIterator:: QTreeWidgetItemIterator ( QTreeWidgetItem * item , QTreeWidgetItemIterator::IteratorFlags flags = All)

构造迭代器为给定 item 使用指定 flags 以确定在迭代期间找到哪些项。迭代器被设为指向 item ,或下一匹配项若 item 不匹配标志。

另请参阅 QTreeWidgetItemIterator::IteratorFlag .

QTreeWidgetItemIterator:: QTreeWidgetItemIterator (const QTreeWidgetItemIterator & it )

构造迭代器为相同 QTreeWidget as it 。当前迭代器项被设为指向当前项在 it .

[noexcept] QTreeWidgetItemIterator:: ~QTreeWidgetItemIterator ()

销毁迭代器。

QTreeWidgetItem *QTreeWidgetItemIterator:: operator* () const

解引用运算符。返回指向当前项的指针。

QTreeWidgetItemIterator &QTreeWidgetItemIterator:: operator++ ()

The prefix ++ operator ( ++it ) advances the iterator to the next matching item and returns a reference to the resulting iterator. Sets the current pointer to nullptr if the current item is the last matching item.

const QTreeWidgetItemIterator QTreeWidgetItemIterator:: operator++ ( int )

后缀 ++ 运算符 (it++) 把迭代器推进到下一匹配项,并返回指向先前当前项迭代器。

QTreeWidgetItemIterator &QTreeWidgetItemIterator:: operator+= ( int n )

使迭代器前进 n 匹配项 (若 n 为负,迭代器后退)。

若当前项超越最后项,当前项指针被设为 nullptr 。返回结果迭代器。

QTreeWidgetItemIterator &QTreeWidgetItemIterator:: operator-- ()

The prefix -- operator ( --it ) advances the iterator to the previous matching item and returns a reference to the resulting iterator. Sets the current pointer to nullptr if the current item is the first matching item.

const QTreeWidgetItemIterator QTreeWidgetItemIterator:: operator-- ( int )

The postfix – operator (it–) makes the preceding matching item current and returns an iterator to the previously current item.

QTreeWidgetItemIterator &QTreeWidgetItemIterator:: operator-= ( int n )

使迭代器后退 n 匹配项 (若 n 为负,迭代器前进)。

若当前项在最后项之前,当前项指针被设为 nullptr 。返回结果迭代器。

QTreeWidgetItemIterator &QTreeWidgetItemIterator:: operator= (const QTreeWidgetItemIterator & it )

赋值。制作副本为 it 并返回其迭代器的引用。