#896 Made the resolution of the slider better

This commit is contained in:
Jacob Støren 2016-09-29 12:01:25 +02:00
parent 585eeef726
commit 8f6744adcb
2 changed files with 7 additions and 1 deletions

View File

@ -115,6 +115,8 @@ void PdmUiDoubleSliderEditor::configureAndUpdateUi(const QString& uiConfigName)
{
uiObject->editorAttribute(field()->fieldHandle(), uiConfigName, &m_attributes);
}
m_slider->setMaximum(m_attributes.m_sliderResolution);
PdmDoubleValidator* pdmValidator = new PdmDoubleValidator(m_attributes.m_minimum, m_attributes.m_maximum, m_attributes.m_decimals, this);
m_lineEdit->setValidator(pdmValidator);
@ -142,6 +144,8 @@ QWidget* PdmUiDoubleSliderEditor::createEditorWidget(QWidget * parent)
connect(m_lineEdit, SIGNAL(editingFinished()), this, SLOT(slotEditingFinished()));
m_slider = new QSlider(Qt::Horizontal, containerWidget);
layout->addWidget(m_lineEdit);
layout->addWidget(m_slider);
@ -218,7 +222,7 @@ int PdmUiDoubleSliderEditor::convertToSliderValue(double value)
{
double exactSliderValue = m_slider->maximum() * (value - m_attributes.m_minimum) / (m_attributes.m_maximum - m_attributes.m_minimum);
int sliderValue = static_cast<int>(exactSliderValue);
int sliderValue = static_cast<int>(nearbyint( exactSliderValue));
sliderValue = qBound(m_slider->minimum(), sliderValue, m_slider->maximum());
return sliderValue;

View File

@ -62,12 +62,14 @@ public:
m_minimum = 0;
m_maximum = 10;
m_decimals = 6;
m_sliderResolution = 2000;
}
public:
double m_minimum;
double m_maximum;
int m_decimals;
int m_sliderResolution;
};