在treeWidget中加入控件

转载于 http://blog.csdn.net/study_more/article/details/7766064

//在treeWidget中加入控件
void Form::addSpaceF()
{
    //删除按钮分区
    treeWidget->removeItemWidget(addSpace,0);

    newItem=new QTreeWidgetItem;
    addSpace=new QTreeWidgetItem;
    addPlate=new QTreeWidgetItem;

    //新增分区
    treeWidget->addTopLevelItem(newItem);

    //板块顺序
    QLineEdit *sortEdit=new QLineEdit;
    treeWidget->setItemWidget(newItem,0,sortEdit );

    //主题名
    QLineEdit *nameEdit=new QLineEdit;
    treeWidget->setItemWidget(newItem,1,nameEdit );

    //版主
    QPushButton *userBtn=new QPushButton(tr("null/addUser"));
    treeWidget->setItemWidget(newItem,2,userBtn );

    //增加分区按钮
    QPushButton *addBtn=new QPushButton(tr("add space"));
    treeWidget->addTopLevelItem(addSpace);
    treeWidget->setItemWidget(addSpace,0,addBtn );
    connect(addBtn,SIGNAL(clicked()),this,SLOT(addSpaceF()));

    //批量编辑
    QCheckBox *editBox=new QCheckBox;
    QPushButton *editBtn=new QPushButton(tr("edit"));
    QPushButton *deleteBtn=new QPushButton(tr("delete"));
    QHBoxLayout *editLayout=new QHBoxLayout;
    editLayout->addWidget(editBox);
    editLayout->addWidget(editBtn);
    editLayout->addWidget(deleteBtn);
    QWidget *edit=new QWidget;
    edit->setLayout(editLayout);
    treeWidget->setItemWidget(newItem,3,edit);

}



你可能感兴趣的:(在treeWidget中加入控件)