소스 검색

BUG: Dynamically resize ctkCollapsibleButton when the style/font is changed

Julien Finet 15 년 전
부모
커밋
208c8f1b32
2개의 변경된 파일25개의 추가작업 그리고 2개의 파일을 삭제
  1. 19 0
      Libs/Widgets/ctkCollapsibleButton.cpp
  2. 6 2
      Libs/Widgets/ctkCollapsibleButton.h

+ 19 - 0
Libs/Widgets/ctkCollapsibleButton.cpp

@@ -594,3 +594,22 @@ void ctkCollapsibleButton::childEvent(QChildEvent* c)
     }
   QWidget::childEvent(c);
 }
+
+//-----------------------------------------------------------------------------
+bool ctkCollapsibleButton::event(QEvent *event)
+{
+  if (event->type() == QEvent::StyleChange
+      || event->type() == QEvent::FontChange
+#ifdef Q_WS_MAC
+      || event->type() == QEvent::MacSizeChange
+#endif
+      )
+    {
+    this->setContentsMargins(0, this->buttonSizeHint().height(),0 , 0);
+    if (this->collapsed())
+      {
+      this->setMaximumHeight(this->sizeHint().height());
+      }
+    }
+  return QAbstractButton::event(event);
+}

+ 6 - 2
Libs/Widgets/ctkCollapsibleButton.h

@@ -105,13 +105,17 @@ public:
   Qt::Alignment indicatorAlignment()const;
 
   /// 
-  /// Reimplement for internal reasons
+  /// Reimplemented for internal reasons
   virtual QSize minimumSizeHint()const;
 
   /// 
-  /// Reimplement for internal reasons
+  /// Reimplemented for internal reasons
   virtual QSize sizeHint()const;
 
+  /// Reimplemented to update the size of the button in case of font/style
+  /// change
+  virtual bool event(QEvent* event);
+
 signals:
   /// 
   /// Signal emitted when the widget is collapsed or expanded.