瀏覽代碼

Merge branch '349-spinbox-crash-in-collapsible-widget'

* 349-spinbox-crash-in-collapsible-widget:
  Fix Qt designer crash when dropping spinbox in ctkCollapsibleGroupBox
Julien Finet 11 年之前
父節點
當前提交
6f4aab0723
共有 2 個文件被更改,包括 16 次插入4 次删除
  1. 7 1
      Libs/Widgets/ctkCollapsibleButton.cpp
  2. 9 3
      Libs/Widgets/ctkCollapsibleGroupBox.cpp

+ 7 - 1
Libs/Widgets/ctkCollapsibleButton.cpp

@@ -141,7 +141,13 @@ void ctkCollapsibleButtonPrivate::setChildVisibility(QWidget* childWidget)
     visible = false;
     }
 
-  childWidget->setVisible(visible);
+  // Setting Qt::WA_WState_Visible to true during child construction can have
+  // undesirable side effects.
+  if (childWidget->testAttribute(Qt::WA_WState_Created) ||
+      !visible)
+    {
+    childWidget->setVisible(visible);
+    }
 
   // setVisible() has set the ExplicitShowHide flag, restore it as we don't want
   // to make it like it was an explicit visible set because we want

+ 9 - 3
Libs/Widgets/ctkCollapsibleGroupBox.cpp

@@ -93,7 +93,7 @@ public:
   /// who is changing children's visibility.
   bool     ForcingVisibility;
   /// Sometimes the creation of the widget is not done inside setVisible,
-  /// as we need to do special processing the first time the button is
+  /// as we need to do special processing the first time the groupBox is
   /// setVisible, we track its created state with the variable
   bool     IsStateCreated;
 
@@ -163,11 +163,17 @@ void ctkCollapsibleGroupBoxPrivate::setChildVisibility(QWidget* childWidget)
     visible = false;
     }
 
-  childWidget->setVisible(visible);
+  // Setting Qt::WA_WState_Visible to true during child construction can have
+  // undesirable side effects.
+  if (childWidget->testAttribute(Qt::WA_WState_Created) ||
+      !visible)
+    {
+    childWidget->setVisible(visible);
+    }
 
   // setVisible() has set the ExplicitShowHide flag, restore it as we don't want
   // to make it like it was an explicit visible set because we want
-  // to allow the children to be explicitly hidden by the user.
+  // to allow any children to be explicitly hidden by the user.
   if ((!childWidget->property("visibilityToParent").isValid() ||
       childWidget->property("visibilityToParent").toBool()))
     {