11 #include <qstyleoption.h> 12 #include <qapplication.h> 15 #include <QMouseEvent> 18 #include <QDesktopWidget> 24 const char* name) :
QSlider(orientation, parent, name)
27 int scr = QApplication::desktop()->screenNumber(
this );
32 connect(
this, SIGNAL( valueChanged(
int) ),
79 if( orientation() == Qt::Vertical )
80 return QString(
"%1").arg( -value() );
82 return QString(
"%1").arg(value());
107 tipString = QString(
"%1%2%3").arg(p).arg(
mapValToString()).arg(s);
114 if(
tooltip->isShown() ) qApp->processEvents();
121 QSlider::mouseMoveEvent(e);
128 :
QLabel( parent,
"toolTipTip",
129 Qt::WStyle_StaysOnTop | Qt::WStyle_Customize |
130 Qt::WStyle_NoBorder | Qt::WStyle_Tool | Qt::WX11BypassWM )
137 setPaletteForegroundColor( QColor(
"Black") );
138 setPaletteBackgroundColor( QColor(
"LightYellow") );
141 setFont( QToolTip::font() );
146 setFrameStyle( Q3Frame::Plain | Q3Frame::Box );
148 setAlignment( Qt::AlignLeft | Qt::AlignTop );
154 connect( slider, SIGNAL( sliderPressed() ),
this, SLOT(
showTooltip() ) );
157 setMouseTracking(
true);
158 connect( slider, SIGNAL( mouseHasMoved() ),
this, SLOT(
update() ) );
161 connect( slider, SIGNAL( sliderReleased() ),
this, SLOT(
hideTooltip() ) );
176 const int TOOLTIP_MARGIN = 4;
181 QRect sliderRect = style()->subControlRect(QStyle::CC_Slider, qstyleoption_cast<QStyleOptionSlider*>(&o), QStyle::SC_SliderHandle,
this);
184 QPoint tooltipTopLeft;
185 if(
slider->orientation() == Qt::Horizontal )
187 tooltipTopLeft = QPoint( sliderRect.right() + TOOLTIP_MARGIN,
189 sliderRect.top() - TOOLTIP_MARGIN -
height() :
190 sliderRect.bottom() + TOOLTIP_MARGIN );
195 sliderRect.left() - TOOLTIP_MARGIN -
width() :
196 sliderRect.right() + TOOLTIP_MARGIN,
197 (sliderRect.top() + sliderRect.bottom())/2 -
height()/2 );
201 tooltipTopLeft =
slider->mapToGlobal( tooltipTopLeft );
204 move( tooltipTopLeft );
205 if( isShown() ) qApp->processEvents();
void setPrefixes(QString prefix1, QString prefix2)
set two prefix values, one for when the value is positive and one for when the value is negative...
virtual QString mapValToString()
subclass DynamicSlider and reimplement this method to change the behavior used to display slider valu...
A more dynamic slider that provides moving tooltips that show the slider value.
void mouseMoveEvent(QMouseEvent *e)
DynamicSlider(Qt::Orientation orientation, QWidget *parent, const char *name=0)
void setZeroString(QString val)
when set, a zero string is shown instead of the current value/prefix/suffix when the slider value is ...
void setSuffix(QString val)
set the suffix that is displayed after the current slider value
void updateTooltipLabel()
void setPrefix(QString val)
set the prefix that is displayed before the current slider value
void setSuffixes(QString suffix1, QString suffix2)
set two suffix values, one for when the value is positive and one for when the value is negative...