소스 검색

Fix title height of ctkCollapsibleGroupBox

A Qt bugs makes it so the checkbox height is not taken into account for
the height of the title SC_GroupBoxContents (see QTBUG #6326)
This is especially a problem with the Mac style.

PE_IndicatorArrowDown doesn't have a pixel metric, the current font height
is used instead of the checkbox height.

Another fix would be to take into account the height of the checkbox by
reimplementing subElementRect for SC_GroupBoxContents and SC_GroupBoxFrame
Julien Finet 13 년 전
부모
커밋
8cd0b184d3
1개의 변경된 파일17개의 추가작업 그리고 3개의 파일을 삭제
  1. 17 3
      Libs/Widgets/ctkCollapsibleGroupBox.cpp

+ 17 - 3
Libs/Widgets/ctkCollapsibleGroupBox.cpp

@@ -36,12 +36,14 @@
 class ctkCollapsibleGroupBoxStyle:public QProxyStyle
 {
   public:
-
+  ctkCollapsibleGroupBoxStyle(QStyle* style = 0) : QProxyStyle(style)
+  {
+  }
   virtual void drawPrimitive(PrimitiveElement pe, const QStyleOption * opt, QPainter * p, const QWidget * widget = 0) const
   {
     if (pe == QStyle::PE_IndicatorCheckBox)
       {
-      const QGroupBox* groupBox= qobject_cast<const QGroupBox*>(widget);
+      const ctkCollapsibleGroupBox* groupBox= qobject_cast<const ctkCollapsibleGroupBox*>(widget);
       if (groupBox)
         {
         this->QProxyStyle::drawPrimitive(groupBox->isChecked() ? QStyle::PE_IndicatorArrowDown : QStyle::PE_IndicatorArrowRight, opt, p, widget);
@@ -50,6 +52,18 @@ class ctkCollapsibleGroupBoxStyle:public QProxyStyle
       }
     this->QProxyStyle::drawPrimitive(pe, opt, p, widget);
   }
+  virtual int pixelMetric(PixelMetric metric, const QStyleOption * option, const QWidget * widget) const
+  {
+    if (metric == QStyle::PM_IndicatorHeight)
+      {
+      const ctkCollapsibleGroupBox* groupBox= qobject_cast<const ctkCollapsibleGroupBox*>(widget);
+      if (groupBox)
+        {
+        return groupBox->fontMetrics().height();
+        }
+      }
+    return this->QProxyStyle::pixelMetric(metric, option, widget);
+  }
 };
 #else
 
@@ -103,7 +117,7 @@ void ctkCollapsibleGroupBoxPrivate::init()
 
   this->MaxHeight = q->maximumHeight();
 #if QT_VERSION >= 0x040600
-  q->setStyle(new ctkCollapsibleGroupBoxStyle);
+  q->setStyle(new ctkCollapsibleGroupBoxStyle(q->style()));
 #else
   this->setStyleSheet(
     "ctkCollapsibleGroupBox::indicator:checked{"