重新实现mousePressEvent即可
/**********************
** imslider.h
**********************/
#ifndef IMSLIDER_H
#define IMSLIDER_H
#include
class QSlider;
class ImSlider : public QSlider
{
Q_OBJECT
public:
ImSlider(QWidget * parent = 0 );
~ImSlider(){;}
virtual bool eventFilter ( QObject *watched, QEvent *event );
protected:
virtual void mousePressEvent ( QMouseEvent * event ) ;
};
#endif
/**********************
** imslider.cpp
**********************/
#include
#include "imslider.h"
ImSlider::ImSlider( QWidget * parent)
:QSlider(parent)
{
}
void ImSlider::mousePressEvent ( QMouseEvent * mouseEvent )
{
if(mouseEvent->button()==Qt::LeftButton && isEnabled())
{
int duration = maximum() - minimum();
int pos = minimum() + duration * ((double)mouseEvent->x() / width());
if(pos != sliderPosition())
{
setValue(pos);
}
// else ok.
}
}
阅读(4782) | 评论(0) | 转发(0) |