Преглед изворни кода

Add ctkCheckablePushButton::checkBoxToggled signal

Julien Finet пре 13 година
родитељ
комит
68d1f9f86a
2 измењених фајлова са 16 додато и 8 уклоњено
  1. 10 8
      Libs/Widgets/ctkCheckablePushButton.cpp
  2. 6 0
      Libs/Widgets/ctkCheckablePushButton.h

+ 10 - 8
Libs/Widgets/ctkCheckablePushButton.cpp

@@ -226,16 +226,18 @@ void ctkCheckablePushButton::setCheckState(Qt::CheckState checkState)
 {
   Q_D(ctkCheckablePushButton);
   Qt::CheckState oldCheckState = d->CheckState;
-  if (checkState != oldCheckState)
+  if (checkState == oldCheckState)
     {
-    d->CheckState = checkState;
-    if (d->CheckBoxFlags & Qt::ItemIsEnabled)
-      {
-      setCheckable(checkState == Qt::Checked);
-      }
-    this->update();
-    emit checkStateChanged(checkState);
+    return;
     }
+  d->CheckState = checkState;
+  if (d->CheckBoxFlags & Qt::ItemIsEnabled)
+    {
+    this->setCheckable(checkState == Qt::Checked);
+    }
+  this->update();
+  emit checkStateChanged(d->CheckState);
+  emit checkBoxToggled(d->CheckState == Qt::Checked);
 }
 
 //-----------------------------------------------------------------------------

+ 6 - 0
Libs/Widgets/ctkCheckablePushButton.h

@@ -42,6 +42,9 @@ class ctkCheckablePushButtonPrivate;
 /// \note In checkBoxControlsButton mode, calling setCheckable instead of
 /// setCheckState may not refresh the button automatically. Use setCheckState
 /// instead.
+/// \note You can automatically check the button when the user checks the
+/// checkbox by connecting the checkBoxToggled(bool) signal with the
+/// setChecked(bool) slot.
 class CTK_WIDGETS_EXPORT ctkCheckablePushButton : public QPushButton
 {
   Q_OBJECT
@@ -81,6 +84,9 @@ public:
   virtual void setCheckBoxUserCheckable(bool b);
 
 signals:
+  /// Fired anytime the checkbox change of state
+  void checkBoxToggled(bool);
+  /// Fired anytime the checkbox change of state
   void checkStateChanged(Qt::CheckState newCheckState);
 
 protected: