timepartwidget.h 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #ifndef TIMEPARTWIDGET_H
  2. #define TIMEPARTWIDGET_H
  3. #include <QWidget>
  4. class MyTimeDelegate;
  5. class QListWidgetItem;
  6. class QScrollBar;
  7. namespace Ui {
  8. class TimePartWidget;
  9. }
  10. class TimePartWidget : public QWidget
  11. {
  12. Q_OBJECT
  13. public:
  14. enum emSection {
  15. HOUR = 0,
  16. MINUTE = 1,
  17. SECOND = 2,
  18. MAX_SECTION
  19. };
  20. public:
  21. explicit TimePartWidget(QWidget *parent = nullptr);
  22. // TimePartWidget(emSection type = emSection::SECOND, QWidget* parent = nullptr);
  23. ~TimePartWidget();
  24. /* 初始化 */
  25. void Init(emSection type);
  26. emSection GetType() const {return m_type;}
  27. void SetTime(const QDateTime& dt);
  28. void SetMaxWidth(int w);
  29. void ScrollToSelect();
  30. /* 设置QSS */
  31. // void setQSS();
  32. protected:
  33. void enterEvent(QEvent* event) override;
  34. void leaveEvent(QEvent* event) override;
  35. signals:
  36. void sigItemClicked(QListWidgetItem* item);
  37. private:
  38. void InitListWidget(int total);
  39. void SelectListItem(int time);
  40. private:
  41. Ui::TimePartWidget *ui;
  42. emSection m_type;
  43. QScopedPointer<MyTimeDelegate> m_delegate;
  44. QScopedPointer<QScrollBar> m_pListBar;
  45. };
  46. #endif // TIMEPARTWIDGET_H