Migration of QtMvvm from github
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

23 lines
570 B

#include "tooltipslider_p.h"
#include <QtCore/QVariant>
#include <QtWidgets/QToolTip>
using namespace QtMvvm;
ToolTipSlider::ToolTipSlider(QWidget *parent) :
QSlider{Qt::Horizontal, parent}
{
setTracking(false);
connect(this, &ToolTipSlider::sliderMoved,
this, &ToolTipSlider::onMoved);
}
void ToolTipSlider::onMoved(int position)
{
auto format = property("valueFormat").toString();
if(format.isEmpty())
format = QStringLiteral("%L1");
auto mPos = mapToGlobal({0,0});
mPos.setX(QCursor::pos().x());
QToolTip::showText(mPos, format.arg(position), this);
}