瀏覽代碼

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{"