浏览代码

Set proper base style for the custom proxy styles

Make sure the proxy styles of ctkCollapsibleGroupBox and ctkCheckBox
use their parent widget style as the base style (or the QApplication style
if no parent). Currently, no update of the base style if the widget changes
parent as it segfaults, probably due to ownership conflicts. Needs more
investigation.
Florian Vichot 12 年之前
父节点
当前提交
3d2248e4f3
共有 2 个文件被更改,包括 17 次插入5 次删除
  1. 4 2
      Libs/Widgets/ctkCheckBox.cpp
  2. 13 3
      Libs/Widgets/ctkCollapsibleGroupBox.cpp

+ 4 - 2
Libs/Widgets/ctkCheckBox.cpp

@@ -20,6 +20,7 @@
 // QT includes
 #include <QProxyStyle>
 #include <QStyleOption>
+#include <QApplication>
 
 // CTK includes
 #include "ctkCheckBox.h"
@@ -135,8 +136,9 @@ ctkCheckBoxPrivate::ctkCheckBoxPrivate(ctkCheckBox &object)
 void ctkCheckBoxPrivate::init()
 {
   Q_Q(ctkCheckBox);
-  this->iconStyle = new ctkCheckBoxStyle(0);
-  this->iconStyle->setParent(q);
+  QWidget * parent = q->parentWidget();
+  QStyle * parentStyle = (parent) ? parent->style() : QApplication::style();
+  this->iconStyle = new ctkCheckBoxStyle(parentStyle);
   q->setStyle(this->iconStyle);
 }
 

+ 13 - 3
Libs/Widgets/ctkCollapsibleGroupBox.cpp

@@ -25,6 +25,7 @@
 #include <QStylePainter>
 #include <QStyleOptionGroupBox>
 #include <QStyle>
+#include <QApplication>
 
 // CTK includes
 #include "ctkCollapsibleGroupBox.h"
@@ -65,8 +66,6 @@ class ctkCollapsibleGroupBoxStyle:public QProxyStyle
     return this->QProxyStyle::pixelMetric(metric, option, widget);
   }
 };
-#else
-
 #endif
 
 //-----------------------------------------------------------------------------
@@ -95,6 +94,11 @@ public:
   /// as we need to do special processing the first time the button is
   /// setVisible, we track its created state with the variable
   bool     IsStateCreated;
+
+#if QT_VERSION >= 0x040600
+  /// Pointer to keep track of the proxy style
+  ctkCollapsibleGroupBoxStyle* ProxyStyle;
+#endif
 };
 
 //-----------------------------------------------------------------------------
@@ -106,6 +110,9 @@ ctkCollapsibleGroupBoxPrivate::ctkCollapsibleGroupBoxPrivate(
   this->IsStateCreated = false;
   this->MaxHeight = 0;
   this->CollapsedHeight = 14;
+#if QT_VERSION >= 0x040600
+  this->ProxyStyle = 0;
+#endif
 }
 
 //-----------------------------------------------------------------------------
@@ -117,7 +124,10 @@ void ctkCollapsibleGroupBoxPrivate::init()
 
   this->MaxHeight = q->maximumHeight();
 #if QT_VERSION >= 0x040600
-  q->setStyle(new ctkCollapsibleGroupBoxStyle(0));
+  QWidget * parent = q->parentWidget();
+  QStyle * parentStyle = (parent) ? parent->style() : QApplication::style();
+  this->ProxyStyle = new ctkCollapsibleGroupBoxStyle(parentStyle);
+  q->setStyle(this->ProxyStyle);
 #else
   this->setStyleSheet(
     "ctkCollapsibleGroupBox::indicator:checked{"