数据上传,下载功能(三)界面QTreeWidget

QTreeWidget

	m_treeWidget = new QTreeWidget;
	//表头可双击的
	m_treeWidget->header()->setClickable(true);
	//可排序的
	m_treeWidget->setSortingEnabled(true);
//	m_treeWidget->sortItems(3, Qt::AscendingOrder);
	//排序图标
	m_treeWidget->header()->setSortIndicatorShown(true);
	//表头标签居中
	m_treeWidget->headerItem()->setTextAlignment(0, Qt::AlignHCenter);
	m_treeWidget->headerItem()->setTextAlignment(1, Qt::AlignHCenter);
	m_treeWidget->headerItem()->setTextAlignment(2, Qt::AlignHCenter);
	m_treeWidget->headerItem()->setTextAlignment(3, Qt::AlignHCenter);
	m_treeWidget->headerItem()->setTextAlignment(4, Qt::AlignHCenter);
	//第0列为ID,隐藏,这样也可以使Tree更像是table
	m_treeWidget->header()->hideSection(0);
	m_treeWidget->header()->hideSection(1);
	//第1列为序号,固定列宽
	m_treeWidget->header()->setResizeMode(1, QHeaderView::ResizeToContents );
	//单行选择
	m_treeWidget->setSelectionMode(QAbstractItemView::SingleSelection);
	m_treeWidget->setHeaderLabels(QStringList()<<QString("ID")<<QString("序号")<<QString("数据名称")<<QString("上传时间")<<QString("上传者")<<QString("IP地址")<<QString("描述"));


添加Item很方便

QStringList strlist;类型

m_treeWidget->addTopLevelItem(new QTreeWidgetItem(strlist));




你可能感兴趣的:(数据上传,下载功能(三)界面QTreeWidget)