ExpertListWidget.cpp 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include "ExpertListWidget.h"
  2. #include <QBoxLayout>
  3. #include <QListWidget>
  4. #include <QLabel>
  5. ExpertListWidget::ExpertListWidget(QWidget *parent) : QWidget(parent)
  6. {
  7. initialize();
  8. initLayout();
  9. refreshList();
  10. }
  11. void ExpertListWidget::refreshList()
  12. {
  13. m_expertListWidget->clear();
  14. for (int i = 1; i <= 100; i++) {
  15. QListWidgetItem *item = new QListWidgetItem;
  16. item->setSizeHint(QSize(200, 60));
  17. m_expertListWidget->addItem(item);
  18. QWidget *w = new QWidget();
  19. w->setStyleSheet("border: 1px solid rgba(0, 0, 0, 0)");
  20. if (i % 2 == 0) {
  21. // w->setStyleSheet("QWidget {background-color: rgb(250, 250, 250);border: 1px solid rgba(0, 0,
  22. // 0, 0);}"
  23. // "QLabel {border: 1px solid rgba(0, 0, 0, 0)}");
  24. } else {
  25. w->setStyleSheet("QWidget {background-color: rgb(244, 244, 255);border: 1px solid rgba(0, 0, 0, 0);}"
  26. "QLabel {border: 1px solid rgba(0, 0, 0, 0)}"
  27. "QWidget::hover {background-color: rgb(244, 244, 0);}");
  28. }
  29. m_expertListWidget->setItemWidget(item, w);
  30. QHBoxLayout *hBox = new QHBoxLayout(w);
  31. hBox->setSpacing(0);
  32. hBox->setMargin(0);
  33. hBox->addWidget(new QLabel(QString::number(i)));
  34. hBox->addSpacing(10);
  35. hBox->addWidget(new QLabel(QString("专家%1").arg(i)));
  36. hBox->addStretch();
  37. }
  38. }
  39. void ExpertListWidget::initialize()
  40. {
  41. m_vBoxLayout = new QVBoxLayout(this);
  42. m_expertListWidget = new QListWidget(this);
  43. m_expertListWidget->setStyleSheet("border: 1px solid rgba(0, 0, 0, 0.073)");
  44. }
  45. void ExpertListWidget::initLayout()
  46. {
  47. m_vBoxLayout->addWidget(m_expertListWidget);
  48. }