#ifndef RANGESLIDER_H #define RANGESLIDER_H #include class RangeSlider : public QWidget { Q_OBJECT public: explicit RangeSlider(int style_ = 0,QWidget *parent = nullptr); void setRange(float min, float max); void setSliderWidth(int width); // 新增方法:设置宽度 float lowerValue() const; float upperValue() const; void setLowerValue(float val); void setUpperValue(float val); float m_lower = 3.5; float m_upper = 6.5; int style = 0; signals: void rangeChanged(float lower, float upper); protected: void paintEvent(QPaintEvent *) override; void mousePressEvent(QMouseEvent *) override; void mouseMoveEvent(QMouseEvent *) override; void mouseReleaseEvent(QMouseEvent *) override; private: float m_min = 0; float m_max = 10; int sliderWidth = 10; // 默认宽度(可以根据需求调整) int handleRadius = 8; enum HandleType { NoHandle, LowerHandle, UpperHandle }; HandleType currentHandle = NoHandle; float valueToY(float value) const; float yToValue(float y) const; HandleType handleHitTest(float y) const; int niceStep(int range, int maxLabels); void drawTicks(QPainter *p); void drawTemperatureStyle(QPainter *p); }; #endif // RANGESLIDER_H