CustomComboBox.h 825 B

12345678910111213141516171819202122232425262728
  1. #pragma once
  2. #include <QComboBox>
  3. class CustomComboBox : public QComboBox
  4. {
  5. Q_OBJECT
  6. public:
  7. CustomComboBox(QWidget* parent = nullptr);
  8. ~CustomComboBox();
  9. void setEditColor(); // 更新样式
  10. void setSavedColor(); // 恢复样式
  11. void setWheelEnabled(bool enabled); // 禁用或启用滚轮
  12. void setRefreshOnClick(bool enabled); // 是否在点击时刷新
  13. void setCurrentIndexByData(const QVariant& data); // 根据数据设置默认项
  14. protected:
  15. bool eventFilter(QObject* watched, QEvent* event) override; // 捕获滚轮事件
  16. void showPopup() override; // 重写下拉框弹出事件
  17. private:
  18. bool m_wheelEnabled = true; // 默认启用滚轮
  19. bool m_refreshOnClick = true; // 默认点击时调用刷新
  20. bool m_firstClick = true;
  21. //QString m_oldValue; // 用于保存上一次的值
  22. int m_oldValue; // 用于保存上一次的值
  23. };