Ver código fonte

Fix the tree view's size width in the settings dialog.

Benjamin Long 13 anos atrás
pai
commit
de720e5fa1

+ 28 - 2
Libs/Widgets/ctkSettingsDialog.cpp

@@ -153,8 +153,10 @@ void ctkSettingsDialog
   parentItem->addChild(newPanelItem);
   d->SettingsStackedWidget->addWidget(panel);
 
-  connect(panel, SIGNAL(settingChanged(QString,QVariant)),
-          this, SLOT(onSettingChanged(QString,QVariant)));
+  this->adjustTreeWidgetToContents();
+
+  connect(panel, SIGNAL(settingChanged(QString, QVariant)),
+          this, SLOT(onSettingChanged(QString, QVariant)));
   panel->setSettings(this->settings());
 }
 
@@ -301,3 +303,27 @@ void ctkSettingsDialog::onDialogButtonClicked(QAbstractButton* button)
       break;
     }
 }
+
+// --------------------------------------------------------------------------
+void ctkSettingsDialog::adjustTreeWidgetToContents()
+{
+  Q_D(const ctkSettingsDialog);
+
+  d->SettingsTreeWidget->resizeColumnToContents(0);
+
+  d->SettingsTreeWidget->setFixedWidth(
+      d->SettingsTreeWidget->QAbstractItemView::sizeHintForColumn(0) +
+      2 * d->SettingsTreeWidget->indentation() +
+      2 * d->SettingsTreeWidget->frameWidth());
+}
+
+// -------------------------------------------------------------------------
+bool ctkSettingsDialog::event(QEvent* event)
+{
+  if (event->type() == QEvent::FontChange ||
+      event->type() == QEvent::StyleChange)
+    {
+    this->adjustTreeWidgetToContents();
+    }
+  return this->Superclass::event(event);
+}

+ 5 - 0
Libs/Widgets/ctkSettingsDialog.h

@@ -58,6 +58,8 @@ public:
   void addPanel(const QString& label, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
   void addPanel(const QString& label, const QIcon& icon, ctkSettingsPanel* panel, ctkSettingsPanel* parentPanel = 0);
 
+  void adjustTreeWidgetToContents();
+
 public slots:
   void setCurrentPanel(ctkSettingsPanel* panel);
   void setCurrentPanel(const QString& label);
@@ -78,6 +80,9 @@ protected slots:
   void onDialogButtonClicked(QAbstractButton* button);
 
 protected:
+  virtual bool event(QEvent *);
+
+protected:
   QScopedPointer<ctkSettingsDialogPrivate> d_ptr;
 
 private: