江苏省建设厅网站官网,网页制作教程答案,外贸网站建设产品,建设厅网站上怎么实名认证QTreeWidget类是创建和管理目录树结构的类#xff0c;QTreeWidget每一个节点都是一个QTreeWidgetItem对象#xff0c;添加一个节点前需先创建。QTreeWidget类是一个便利类#xff0c;它提供了一个标准的树widget#xff0c;具有经典的基于item的界面#xff0c;类似于Qt 3…QTreeWidget类是创建和管理目录树结构的类QTreeWidget每一个节点都是一个QTreeWidgetItem对象添加一个节点前需先创建。QTreeWidget类是一个便利类它提供了一个标准的树widget具有经典的基于item的界面类似于Qt 3中的QListView类所使用的界面。这个类基于Qt的Model/View架构并使用默认模型来保存项目每个项目都是一个QTreeWidgetItem。 不需要模型/视图框架的灵活性的开发人员可以使用这个类非常容易地创建简单的分层列表。更灵活的方法是将QTreeView与标准项模型相结合。这允许将数据的存储与其表示分开。
常用函数
addTopLevelItem(QTreeWidgetItem *item)将该项添加为小部件中的顶级项addTopLevelItems(const QListQTreeWidgetItem * items)将项目列表添加为小部件中的顶级项目closePersistentEditor(QTreeWidgetItem *item, int column 0)关闭给定列中项目的持久编辑器。如果没有为项和列的组合打开持久编辑器则此函数无效columnCount() const返回列数currentColumn() const返回树小部件中的当前列;currentItem() const返回树部件中的当前项editItem(QTreeWidgetItem *item, int column 0)开始编辑给定列中的项目(如果它是可编辑的)findItems(const QString text, Qt::MatchFlags flags, int column 0) const使用给定标志返回给定列中与给定文本匹配的项的列表headerItem() const返回树部件标题所用的项indexOfTopLevelItem(QTreeWidgetItem *item) const返回给定的顶级项的索引如果找不到该项则返回-1insertTopLevelItem(int index, QTreeWidgetItem *item)在视图的最顶层的索引处插入项目insertTopLevelItems(int index, const QListQTreeWidgetItem * items)在视图的最顶层的索引处插入项目列表invisibleRootItem() const返回树小部件的不可见根项isPersistentEditorOpen(QTreeWidgetItem *item, int column 0) const返回列中的项是否打开持久编辑器itemAbove(const QTreeWidgetItem *item) const返回给定项之上的项itemAt(const QPoint p) const返回一个指向坐标p处元素的指针。坐标是相对于树部件的视口()的itemAt(int x, int y) constitemBelow(const QTreeWidgetItem *item) const返回给定项下方的项itemWidget(QTreeWidgetItem *item, int column) const返回显示在item和给定列指定的单元格中的小部件openPersistentEditor(QTreeWidgetItem *item, int column 0)为给定列中的项打开一个持久编辑器removeItemWidget(QTreeWidgetItem *item, int column)删除给定列中给定项中设置的小部件selectedItems() const返回所有选定的非隐藏项的列表setColumnCount(int columns)设置列数setCurrentItem(QTreeWidgetItem *item)设置树部件中的当前项setCurrentItem(QTreeWidgetItem *item, int column)设置树部件中的当前项setCurrentItem(QTreeWidgetItem *item, int column, QItemSelectionModel::SelectionFlags command)设置树部件中的当前项setHeaderItem(QTreeWidgetItem *item)设置树部件的标题项setHeaderLabel(const QString label)在标题中为labels列表中的每个项目添加一列并为每一列设置标签setHeaderLabels(const QStringList labels)在标题中为labels列表中的每个项目添加一列并为每一列设置标签setItemWidget(QTreeWidgetItem *item, int column, QWidget *widget)设置给定的小部件在给定的项和列指定的单元格中显示sortColumn() const返回用于对小部件内容进行排序的列。sortItems(int column, Qt::SortOrder order)根据给定列中的值按指定顺序对小部件中的项进行排序takeTopLevelItem(int index)删除树中给定索引处的顶层元素并返回该元素否则返回nullptrtopLevelItem(int index) const返回给定索引处的顶级项如果项不存在则返回nullptrtopLevelItemCount() const返回顶级元素的数量visualItemRect(const QTreeWidgetItem *item) const返回视口中每个元素所占据的矩形
槽函数
clear()删除树部件的所有项collapseItem(const QTreeWidgetItem *item)关闭项目。这将导致包含子项的树被折叠expandItem(const QTreeWidgetItem *item)展开项目。这将导致包含该项子项的树被扩展scrollToItem(const QTreeWidgetItem *item, QAbstractItemView::ScrollHint hint EnsureVisible)确保项目可见并在必要时使用指定的提示滚动视图
信号
currentItemChanged(QTreeWidgetItem *current, QTreeWidgetItem *previous)当当前元素发生变化时就会发出这个信号itemActivated(QTreeWidgetItem *item, int column)当用户通过单击或双击或按下特殊键来激活一个项目时就会发出此信号itemChanged(QTreeWidgetItem *item, int column)当指定项中的列的内容发生更改时就会发出此信号itemClicked(QTreeWidgetItem *item, int column)当用户在widget内部单击时就会发出这个信号itemCollapsed(QTreeWidgetItem *item)这个信号是在折叠指定的元素而不显示其子项时发出的itemDoubleClicked(QTreeWidgetItem *item, int column)当用户在widget内部双击时就会发出这个信号itemEntered(QTreeWidgetItem *item, int column)当鼠标光标在指定的列上输入一个项目时就会发出这个信号。QTreeWidget鼠标跟踪需要启用此功能才能工作itemExpanded(QTreeWidgetItem *item)当指定项展开时会发出此信号以便显示其所有子项itemPressed(QTreeWidgetItem *item, int column)当用户在widget内按下鼠标按钮时就会发出这个信号itemSelectionChanged()当树部件中的选择发生变化时就会发出这个信号。可以通过selectedItems()找到当前选区
QTreeWidgetItem 树小部件项用于保存树小部件的信息行。行通常包含几列数据每列可以包含一个文本标签和一个图标。 QTreeWidgetItem类是一个方便类它取代了QListViewItem类在Qt 3。它提供了一个与QTreeWidget类一起使用的项。
QTreeWidgetItem常用函数
addChild(QTreeWidgetItem *child)将子项添加到子项列表中;addChildren(const QListQTreeWidgetItem * children)将给定的子项列表附加到项上checkState(int column) const返回给定列中标签的检查状态child(int index) const返回子项列表中指定索引处的项childCount() const返回子项的数量columnCount() const返回项中的列数data(int column, int role) const返回项的列和角色的值removeChild(QTreeWidgetItem *child)删除由child指定的给定项。被删除的项目不会被删除setData(int column, int role, const QVariant value)设置项的列和角色的值为给定的值setExpanded(bool expand)如果expand为true则展开项否则折叠项setText(int column, const QString text)将在给定列中显示的文本设置为给定文本takeChild(int index)删除索引处的项并返回否则返回0treeWidget() const返回包含该项的树部件setFlags(Qt::ItemFlags flags)将项的标志设置为给定的标志。它们决定了是否可以选择或修改
图片示例 代码示例 QTreeWidgetDialog.h
#ifndef QTREEWIDGETDIALOG_H
#define QTREEWIDGETDIALOG_H#include QDialog
#include QTreeWidgetItem
namespace Ui
{class QTreeWidgetDialog;
}class QTreeWidgetDialog : public QDialog
{Q_OBJECTpublic:explicit QTreeWidgetDialog(QWidget* parent nullptr);~QTreeWidgetDialog();void init();private slots:void on_add_clicked();void on_remove_clicked();void on_treeWidget_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous);void on_pushButton_clicked();void changeItemCaption(QTreeWidgetItem* item);private:Ui::QTreeWidgetDialog* ui;
};#endif // QTREEWIDGETDIALOG_H
QTreeWidgetDialog.cpp
#include QTreeWidgetDialog.h
#include ui_QTreeWidgetDialog.h
#include QTreeWidget
QTreeWidgetDialog::QTreeWidgetDialog(QWidget* parent): QDialog(parent), ui(new Ui::QTreeWidgetDialog)
{ui-setupUi(this);ui-treeWidget-clear();init();
}QTreeWidgetDialog::~QTreeWidgetDialog()
{delete ui;
}void QTreeWidgetDialog::init()
{QTreeWidgetItem* item new QTreeWidgetItem(1001);QIcon icon;icon.addFile();item-setIcon(0, icon);item-setText(0, demo);item-setText(1, type1001);item-setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable|Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);item-setCheckState(0, Qt::Checked);item-setData(0, Qt::UserRole, QVariant(aaaa));ui-treeWidget-addTopLevelItem(item);
}void QTreeWidgetDialog::on_add_clicked()
{QTreeWidgetItem* curItem ui-treeWidget-currentItem();QTreeWidgetItem* newItem new QTreeWidgetItem(1002);QIcon icon;icon.addFile();newItem-setIcon(0, icon);newItem-setText(0, subdemo);newItem-setText(1, type1002);newItem-setFlags(Qt::ItemIsSelectable | Qt::ItemIsUserCheckable|Qt::ItemIsEnabled | Qt::ItemIsAutoTristate);newItem-setCheckState(0, Qt::Checked);newItem-setData(0, Qt::UserRole, QVariant(aaaa));curItem-addChild(newItem);
}void QTreeWidgetDialog::on_remove_clicked()
{//删除顶部节点// ui-treeWidget-takeTopLevelItem(0);QTreeWidgetItem* curItem ui-treeWidget-currentItem();QTreeWidgetItem* parentItem curItem-parent();parentItem-removeChild(curItem);delete curItem;
}//节点变化信号
void QTreeWidgetDialog::on_treeWidget_currentItemChanged(QTreeWidgetItem* current, QTreeWidgetItem* previous)
{Q_UNUSED(previous);if(current NULL) {return ;}int var current-type();switch(var) {case 1001:ui-add-setEnabled(true);ui-remove-setEnabled(false);break;case 1002:ui-add-setEnabled(true);ui-remove-setEnabled(true);break;}
}//遍历节点
void QTreeWidgetDialog::on_pushButton_clicked()
{int countui-treeWidget-topLevelItemCount();for(int i0; icount; i) {QTreeWidgetItem* item ui-treeWidget-topLevelItem(i);changeItemCaption(item);}
}void QTreeWidgetDialog::changeItemCaption(QTreeWidgetItem* item)
{QString str * item-text(0);item-setText(0, str);int childCount item-childCount();if(childCount 0) {for(int i0; ichildCount; i) {changeItemCaption(item-child(i));}}
} 文章转载自: http://www.morning.spkw.cn.gov.cn.spkw.cn http://www.morning.zrwlz.cn.gov.cn.zrwlz.cn http://www.morning.klzt.cn.gov.cn.klzt.cn http://www.morning.zwsgl.cn.gov.cn.zwsgl.cn http://www.morning.thrtt.cn.gov.cn.thrtt.cn http://www.morning.hcwjls.com.gov.cn.hcwjls.com http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn http://www.morning.ynwdk.cn.gov.cn.ynwdk.cn http://www.morning.lmxrt.cn.gov.cn.lmxrt.cn http://www.morning.kfrhh.cn.gov.cn.kfrhh.cn http://www.morning.zxfr.cn.gov.cn.zxfr.cn http://www.morning.rwtlj.cn.gov.cn.rwtlj.cn http://www.morning.hhqtq.cn.gov.cn.hhqtq.cn http://www.morning.msfqt.cn.gov.cn.msfqt.cn http://www.morning.mxmdd.cn.gov.cn.mxmdd.cn http://www.morning.rfrxt.cn.gov.cn.rfrxt.cn http://www.morning.wrbx.cn.gov.cn.wrbx.cn http://www.morning.xrqkm.cn.gov.cn.xrqkm.cn http://www.morning.wgcng.cn.gov.cn.wgcng.cn http://www.morning.rshijie.com.gov.cn.rshijie.com http://www.morning.zttjs.cn.gov.cn.zttjs.cn http://www.morning.srltq.cn.gov.cn.srltq.cn http://www.morning.qcbhb.cn.gov.cn.qcbhb.cn http://www.morning.mzhh.cn.gov.cn.mzhh.cn http://www.morning.mfnsn.cn.gov.cn.mfnsn.cn http://www.morning.pxbky.cn.gov.cn.pxbky.cn http://www.morning.yckwt.cn.gov.cn.yckwt.cn http://www.morning.mqwdh.cn.gov.cn.mqwdh.cn http://www.morning.yrbp.cn.gov.cn.yrbp.cn http://www.morning.txjrc.cn.gov.cn.txjrc.cn http://www.morning.sxygc.cn.gov.cn.sxygc.cn http://www.morning.hxwrs.cn.gov.cn.hxwrs.cn http://www.morning.qqrlz.cn.gov.cn.qqrlz.cn http://www.morning.jcfg.cn.gov.cn.jcfg.cn http://www.morning.dljujia.com.gov.cn.dljujia.com http://www.morning.wtbzt.cn.gov.cn.wtbzt.cn http://www.morning.gwjqq.cn.gov.cn.gwjqq.cn http://www.morning.ytnn.cn.gov.cn.ytnn.cn http://www.morning.rnzgf.cn.gov.cn.rnzgf.cn http://www.morning.pylpd.cn.gov.cn.pylpd.cn http://www.morning.mpscg.cn.gov.cn.mpscg.cn http://www.morning.knngw.cn.gov.cn.knngw.cn http://www.morning.ailvturv.com.gov.cn.ailvturv.com http://www.morning.zhishizf.cn.gov.cn.zhishizf.cn http://www.morning.dphmj.cn.gov.cn.dphmj.cn http://www.morning.nytpt.cn.gov.cn.nytpt.cn http://www.morning.ztfzm.cn.gov.cn.ztfzm.cn http://www.morning.rbgqn.cn.gov.cn.rbgqn.cn http://www.morning.pwghp.cn.gov.cn.pwghp.cn http://www.morning.rfjmy.cn.gov.cn.rfjmy.cn http://www.morning.mjdbd.cn.gov.cn.mjdbd.cn http://www.morning.ttfh.cn.gov.cn.ttfh.cn http://www.morning.qphcq.cn.gov.cn.qphcq.cn http://www.morning.skksz.cn.gov.cn.skksz.cn http://www.morning.mntxalcb.com.gov.cn.mntxalcb.com http://www.morning.lpzyq.cn.gov.cn.lpzyq.cn http://www.morning.jqrhz.cn.gov.cn.jqrhz.cn http://www.morning.kcyxs.cn.gov.cn.kcyxs.cn http://www.morning.trrpb.cn.gov.cn.trrpb.cn http://www.morning.tgts.cn.gov.cn.tgts.cn http://www.morning.rsjf.cn.gov.cn.rsjf.cn http://www.morning.jczjf.cn.gov.cn.jczjf.cn http://www.morning.qrlkt.cn.gov.cn.qrlkt.cn http://www.morning.zpdjh.cn.gov.cn.zpdjh.cn http://www.morning.gjws.cn.gov.cn.gjws.cn http://www.morning.gmplp.cn.gov.cn.gmplp.cn http://www.morning.nmfml.cn.gov.cn.nmfml.cn http://www.morning.guofenmai.cn.gov.cn.guofenmai.cn http://www.morning.ccdyc.cn.gov.cn.ccdyc.cn http://www.morning.ntnml.cn.gov.cn.ntnml.cn http://www.morning.xwlmg.cn.gov.cn.xwlmg.cn http://www.morning.pwdgy.cn.gov.cn.pwdgy.cn http://www.morning.hmmnb.cn.gov.cn.hmmnb.cn http://www.morning.pmhln.cn.gov.cn.pmhln.cn http://www.morning.hsgxj.cn.gov.cn.hsgxj.cn http://www.morning.clpdm.cn.gov.cn.clpdm.cn http://www.morning.jlboyuan.cn.gov.cn.jlboyuan.cn http://www.morning.zpzys.cn.gov.cn.zpzys.cn http://www.morning.qscsy.cn.gov.cn.qscsy.cn http://www.morning.yqwsd.cn.gov.cn.yqwsd.cn