设置标签相关函数
void QTreeWidget::setHeaderItem (QTreeWidgetItem * item ); void QTreeWidget::setHeaderLabel ( constQString & label ); void QTreeWidget::setHeaderLabels ( constQStringList & labels );
示例:
QTreeWidget* tree = new QTreeWidget(); QStringList header; header<<"column1"<<"column2"<<"column3"; tree->setHeaderLabels(header); tree->show();
效果:
添加列表数据
通过QTreeWidgetItem类的setText()实现
QTreeWidget* tree = new QTreeWidget(); QStringList header; header<<"column1"<<"column2"<<"column3"; tree->setHeaderLabels(header); QTreeWidgetItem item1(tree); //在树根下创建Item1节点,等价于: (void) new QTreeWidgetItem(tree,QStringList()<<"1"<<"2"<<"3"); item1.setText(0,"1"); item1.setText(1,"2"); item1.setText(2,"3"); QTreeWidgetItem item2(tree); //在树根下创建Item2节点 item2.setText(0,"4"); item2.setText(1,"5"); item2.setText(2,"6"); QTreeWidgetItem item3(&item2); //在Item2下创建Item3节点 item3.setText(0,"child"); tree->show();
QTabWidget组件添加页面示例
QWidget w; QTabWidget t(&w); QPushButton btn("test"); t.addTab(&btn,"1st"); w.show();
常用函数
void setTabPosition ( TabPosition ); //设置标签tab位置 void setTabShape ( TabShape s ); //设置标签tab外观 void removeTab ( int index ); //移除掉某个index页面 insertTab ( int index, QWidget * page, const QIcon & icon, const QString & label ); //插入页面 setTabsClosable ( bool closeable ); //设置每个页面是否有关闭按钮 setEnabled ( bool ); //设置所有页面是否可操作,为false则显示灰色