设置标签相关函数
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则显示灰色
setTabEnabled ( int index, boolenable ); //设置单个tab页面是否可操作
预定义信号函数
void currentChanged ( int index );
//当前页面发生改变后发送信号,index为新页面下标
void tabCloseRequested ( int index );
//当点击index页面的关闭按钮时,发送信号