ProjectListWidget.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #include "ProjectListWidget.h"
  2. #include <Widgets/LineEdit.h>
  3. #include <Widgets/Button.h>
  4. #include <Widgets/TreeView.h>
  5. #include <QBoxLayout>
  6. #include <QListWidget>
  7. #include <QLabel>
  8. #include <QDebug>
  9. ProjectListWidget::ProjectListWidget(QWidget *parent) : QWidget(parent)
  10. {
  11. initialize();
  12. initLayout();
  13. connectSiganlsAndSlots();
  14. refreshList();
  15. }
  16. void ProjectListWidget::refreshList()
  17. {
  18. for (int i = 1; i <= 20; i++) {
  19. QTreeWidgetItem *item1 = new QTreeWidgetItem({ QString("工程%1").arg(i) });
  20. m_treeWidget->addTopLevelItem(item1);
  21. item1->addChildren({ new QTreeWidgetItem({ "能力需求评估" }), new QTreeWidgetItem({ "技术措施评估" }),
  22. new QTreeWidgetItem({ "技术方案评估" }) });
  23. }
  24. m_treeWidget->expandAll();
  25. return;
  26. // m_listWidget->clear();
  27. // for (int i = 1; i <= 100; i++) {
  28. // QListWidgetItem *item = new QListWidgetItem;
  29. // item->setSizeHint(QSize(200, 80));
  30. // m_listWidget->addItem(item);
  31. // ProjectListItemWidget *w = new ProjectListItemWidget();
  32. // w->setIndex(i);
  33. // w->setName(QString("工程%1").arg(i));
  34. // m_listWidget->setItemWidget(item, w);
  35. // }
  36. }
  37. void ProjectListWidget::initialize()
  38. {
  39. QPalette pal(palette());
  40. pal.setColor(QPalette::Background, QColor("#eeeeee"));
  41. setAutoFillBackground(true);
  42. setPalette(pal);
  43. m_vBoxLayout = new QVBoxLayout(this);
  44. // m_listWidget = new QListWidget(this);
  45. // m_listWidget->setAlternatingRowColors(true);
  46. // m_listWidget->setStyleSheet("QListWidget {border: 1px solid rgba(0, 0, 0, 0.073);background: rgb(255, 255, "
  47. // "255);alternate-background-color: rgb(244, 244, 255);}");
  48. m_treeWidget = new TreeWidget(this);
  49. m_treeWidget->setHeaderHidden(true);
  50. }
  51. void ProjectListWidget::initLayout()
  52. {
  53. m_vBoxLayout->setMargin(0);
  54. // m_vBoxLayout->addWidget(m_listWidget);
  55. m_vBoxLayout->addWidget(m_treeWidget);
  56. }
  57. void ProjectListWidget::connectSiganlsAndSlots()
  58. {
  59. // connect(m_listWidget, &QListWidget::itemDoubleClicked, this, &ProjectListWidget::slotItemDoubleClicked);
  60. // connect(m_listWidget, &QListWidget::itemClicked, this, &ProjectListWidget::slotItemClicked);
  61. // connect(m_listWidget, &QListWidget::currentItemChanged, this, &ProjectListWidget::slotCurrentItemChanged);
  62. // connect(m_listWidget, &QListWidget::currentRowChanged, this, &ProjectListWidget::slotCurrentRowChanged);
  63. // connect(m_listWidget, &QListWidget::itemSelectionChanged, this, &ProjectListWidget::slotItemSelectionChanged);
  64. }
  65. void ProjectListWidget::slotItemDoubleClicked(QListWidgetItem *item)
  66. {
  67. qDebug() << __FUNCTION__ << __LINE__;
  68. }
  69. void ProjectListWidget::slotItemClicked(QListWidgetItem *item)
  70. {
  71. qDebug() << __FUNCTION__ << __LINE__;
  72. }
  73. void ProjectListWidget::slotCurrentItemChanged(QListWidgetItem *current, QListWidgetItem *previous)
  74. {
  75. qDebug() << __FUNCTION__ << __LINE__;
  76. }
  77. void ProjectListWidget::slotCurrentRowChanged(int currentRow)
  78. {
  79. qDebug() << __FUNCTION__ << __LINE__;
  80. }
  81. void ProjectListWidget::slotItemSelectionChanged()
  82. {
  83. qDebug() << __FUNCTION__ << __LINE__;
  84. }
  85. ProjectListItemWidget::ProjectListItemWidget(QWidget *parent) : QWidget(parent)
  86. {
  87. initialize();
  88. initLayout();
  89. }
  90. void ProjectListItemWidget::initialize()
  91. {
  92. m_hBoxLayout = new QHBoxLayout(this);
  93. m_vBoxLayout = new QVBoxLayout();
  94. m_indexLabel = new QLabel(this);
  95. m_indexLabel->setFixedWidth(20);
  96. m_indexLabel->setObjectName("indexLabel");
  97. m_nameLabel = new QLabel(this);
  98. m_nameLabel->setObjectName("nameLabel");
  99. m_typeLabel1 = new QLabel(this);
  100. m_typeLabel1->setObjectName("typeLabel1");
  101. m_typeLabel1->setContentsMargins(10, 0, 0, 0);
  102. m_typeLabel2 = new QLabel(this);
  103. m_typeLabel2->setObjectName("typeLabel2");
  104. m_typeLabel2->setContentsMargins(10, 0, 0, 0);
  105. m_typeLabel1->setText("能力与技术重要度评估");
  106. m_typeLabel2->setText("技术方案评估");
  107. setStyleSheet("#indexLabel {font-size:14px}"
  108. "#nameLabel {color:#1196db; font-size:14px; font:bold}"
  109. "#typeLabel1 {color: gray;}"
  110. "#typeLabel2 {color: gray;}");
  111. }
  112. void ProjectListItemWidget::initLayout()
  113. {
  114. m_hBoxLayout->addWidget(m_indexLabel);
  115. m_hBoxLayout->addLayout(m_vBoxLayout);
  116. m_hBoxLayout->addStretch();
  117. m_vBoxLayout->addWidget(m_nameLabel);
  118. m_vBoxLayout->addWidget(m_typeLabel1);
  119. m_vBoxLayout->addWidget(m_typeLabel2);
  120. }
  121. void ProjectListItemWidget::setIndex(int index)
  122. {
  123. m_index = index;
  124. m_indexLabel->setText(QString::number(index));
  125. }
  126. int ProjectListItemWidget::index() const
  127. {
  128. return m_index;
  129. }
  130. void ProjectListItemWidget::setName(const QString name)
  131. {
  132. m_name = name;
  133. m_nameLabel->setText(name);
  134. }
  135. const QString ProjectListItemWidget::name() const
  136. {
  137. return m_name;
  138. }