Prechádzať zdrojové kódy

ENH: Fix sizePolicy of ctkRangeWidget and ctkSliderWidget

they should have the same policy as ctkRangeSlider and QSlider
Julien Finet 14 rokov pred
rodič
commit
71419a9c31

+ 1 - 1
Libs/Widgets/Resources/UI/ctkRangeWidget.ui

@@ -11,7 +11,7 @@
    </rect>
   </property>
   <property name="sizePolicy">
-   <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+   <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>

+ 5 - 8
Libs/Widgets/Resources/UI/ctkSliderWidget.ui

@@ -6,12 +6,12 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>226</width>
-    <height>32</height>
+    <width>183</width>
+    <height>27</height>
    </rect>
   </property>
   <property name="sizePolicy">
-   <sizepolicy hsizetype="Expanding" vsizetype="Preferred">
+   <sizepolicy hsizetype="Expanding" vsizetype="Fixed">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
@@ -19,12 +19,9 @@
   <property name="windowTitle">
    <string>ctkSliderWidget</string>
   </property>
-  <layout class="QHBoxLayout" name="horizontalLayout">
-   <property name="spacing">
-    <number>2</number>
-   </property>
+  <layout class="QHBoxLayout">
    <property name="margin">
-    <number>2</number>
+    <number>0</number>
    </property>
    <item>
     <widget class="ctkDoubleSlider" name="Slider">

+ 3 - 0
Libs/Widgets/ctkDoubleRangeSlider.cpp

@@ -86,6 +86,9 @@ void ctkDoubleRangeSliderPrivate::init()
   this->MaxValue = this->Slider->maximumValue();
   this->SingleStep = this->Slider->singleStep();
 
+  p->setSizePolicy(QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed,
+                               QSizePolicy::Slider));
+
   this->connectSlider();
 }
 

+ 5 - 6
Libs/Widgets/ctkRangeWidget.cpp

@@ -323,8 +323,7 @@ void ctkRangeWidget::setMinimumValue(double _value)
   bool isChanging = d->Changing;
   d->Changing = false;
   d->MinimumSpinBox->setValue(_value);
-  // Why do we need to set the value to the slider ?
-  //d->Slider->setValue(d->SpinBox->value());
+
   Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
   // restore the prop
   d->Changing = isChanging;
@@ -339,8 +338,7 @@ void ctkRangeWidget::setMaximumValue(double _value)
   bool isChanging = d->Changing;
   d->Changing = false;
   d->MaximumSpinBox->setValue(_value);
-  // Why do we need to set the value to the slider ?
-  //d->Slider->setValue(d->SpinBox->value());
+
   Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
   // restore the prop
   d->Changing = isChanging;
@@ -354,10 +352,11 @@ void ctkRangeWidget::setValues(double newMinimumValue, double newMaximumValue)
   // signal valueChanged if changeValue() is called
   bool isChanging = d->Changing;
   d->Changing = false;
+  // the pb here is that setting the spinbox separately will fired 2 signals and
+  // between the state will be inconsistent
   d->MinimumSpinBox->setValue(newMinimumValue);
   d->MaximumSpinBox->setValue(newMaximumValue);
-  // Why do we need to set the value to the slider ?
-  //d->Slider->setValue(d->SpinBox->value());
+
   Q_ASSERT(d->equal(d->Slider->minimumValue(), d->MinimumSpinBox->value()));
   Q_ASSERT(d->equal(d->Slider->maximumValue(), d->MaximumSpinBox->value()));
   // restore the prop