ComboBox.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. #ifndef COMBOBOX_H
  2. #define COMBOBOX_H
  3. #include <QComboBox>
  4. #include <QStyledItemDelegate>
  5. struct UserInfo
  6. {
  7. QString name;
  8. QString number;
  9. QIcon icon;
  10. bool isonline;
  11. };
  12. class ComboListModel : public QAbstractListModel
  13. {
  14. Q_OBJECT
  15. public:
  16. explicit ComboListModel(QObject *parent = 0);
  17. ~ComboListModel();
  18. QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
  19. int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  20. void setModelData(const QList<UserInfo> &);
  21. private:
  22. QList<UserInfo> m_infoList;
  23. };
  24. class ComboBox : public QComboBox
  25. {
  26. Q_OBJECT
  27. public:
  28. explicit ComboBox(QWidget *parent = nullptr);
  29. signals:
  30. };
  31. class ComboListDelegate : public QStyledItemDelegate
  32. {
  33. Q_OBJECT
  34. public:
  35. explicit ComboListDelegate(QObject *parent = 0);
  36. ~ComboListDelegate();
  37. void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override;
  38. QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override;
  39. private:
  40. qreal m_radius = 8;
  41. };
  42. class ComboTableModel : public QAbstractTableModel
  43. {
  44. Q_OBJECT
  45. public:
  46. explicit ComboTableModel(QObject *parent = nullptr);
  47. QVariant data(const QModelIndex &index, int role) const override;
  48. int rowCount(const QModelIndex &parent = QModelIndex()) const override;
  49. int columnCount(const QModelIndex &parent = QModelIndex()) const override;
  50. QVariant headerData(int section, Qt::Orientation orientation, int role) const override;
  51. void setModelData(const QList<UserInfo> &data, int column);
  52. Qt::ItemFlags flags(const QModelIndex &index) const override;
  53. private:
  54. QList<UserInfo> m_infoList;
  55. int m_column;
  56. };
  57. class ComboBoxMenu : public QWidget
  58. {
  59. public:
  60. explicit ComboBoxMenu(QWidget *parent = nullptr);
  61. };
  62. #endif // COMBOBOX_H