image.png

    1. Widget::Widget(QWidget *parent)
    2. : QWidget(parent)
    3. , ui(new Ui::Widget)
    4. {
    5. ui->setupUi(this);
    6. //------------添加头------------//
    7. QList<QString> list;
    8. list << "英雄名" << "英雄介绍";
    9. ui->treeWidget->setHeaderLabels(QStringList() << "英雄名" << "英雄介绍");
    10. //------------添加项目------------//
    11. // 添加顶层项目
    12. QTreeWidgetItem* Item_Power = new QTreeWidgetItem(QStringList()<< "力量");
    13. QTreeWidgetItem* Item_Quick = new QTreeWidgetItem(QStringList()<< "敏捷");
    14. QTreeWidgetItem* Item_Mental = new QTreeWidgetItem(QStringList()<< "智力");
    15. ui->treeWidget->addTopLevelItem(Item_Power);
    16. ui->treeWidget->addTopLevelItem(Item_Quick);
    17. ui->treeWidget->addTopLevelItem(Item_Mental);
    18. // 追加子项目
    19. QStringList heroP1,heroP2;
    20. heroP1 << "刚背猪" << "前排坦克,能在吸收伤害的同时造成可观的范围输出";
    21. heroP2 << "船长" << "前排坦克,能肉能输出能控场的全能英雄";
    22. QStringList heroQ1,heroQ2;
    23. heroQ1 << "月骑" << "中排物理输出,可攻击多个目标";
    24. heroQ2 << "小鱼人" << "擅长偷取敌人的属性来增强自身";
    25. QStringList heroM1,heroM2;
    26. heroM1 << "死灵法师" << "前排法师坦克,魔法抗性较高,拥有治疗技能";
    27. heroM2 << "巫医" << "后排辅助法师,可以使用奇特的巫术诅咒敌人与治疗队友";
    28. QTreeWidgetItem* P1 = new QTreeWidgetItem(heroP1);
    29. Item_Power->addChild(P1);
    30. QTreeWidgetItem* P2 = new QTreeWidgetItem(heroP2);
    31. Item_Power->addChild(P2);
    32. QTreeWidgetItem* Q1 = new QTreeWidgetItem(heroQ1);
    33. Item_Quick->addChild(Q1);
    34. QTreeWidgetItem* Q2 = new QTreeWidgetItem(heroQ2);
    35. Item_Quick->addChild(Q2);
    36. QTreeWidgetItem* M1 = new QTreeWidgetItem(heroM1);
    37. Item_Mental->addChild(M1);
    38. QTreeWidgetItem* M2 = new QTreeWidgetItem(heroM2);
    39. Item_Mental->addChild(M2);
    40. }