瀏覽代碼

Auto-resize [Name] column to match contents length

nherlambang 14 年之前
父節點
當前提交
ff1a64966a
共有 2 個文件被更改,包括 19 次插入1 次删除
  1. 16 1
      Libs/DICOM/Widgets/ctkDICOMAppWidget.cpp
  2. 3 0
      Libs/DICOM/Widgets/ctkDICOMAppWidget.h

+ 16 - 1
Libs/DICOM/Widgets/ctkDICOMAppWidget.cpp

@@ -52,7 +52,6 @@ public:
 // ctkDICOMAppWidgetPrivate methods
 
 ctkDICOMAppWidgetPrivate::ctkDICOMAppWidgetPrivate(){
-  
   DICOMDatabase = QSharedPointer<ctkDICOMDatabase> (new ctkDICOMDatabase);
   DICOMIndexer = QSharedPointer<ctkDICOMIndexer> (new ctkDICOMIndexer);
 }
@@ -80,6 +79,9 @@ ctkDICOMAppWidget::ctkDICOMAppWidget(QWidget* _parent):Superclass(_parent),
   d->treeView->setSortingEnabled(true);
   d->treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
 
+  connect(d->treeView, SIGNAL(collapsed(QModelIndex)), this, SLOT(onTreeCollapsed(QModelIndex)));
+  connect(d->treeView, SIGNAL(expanded(QModelIndex)), this, SLOT(onTreeExpanded(QModelIndex)));
+
   //Set toolbar button style
   d->toolBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
 
@@ -156,6 +158,7 @@ void ctkDICOMAppWidget::setDatabaseDirectory(const QString& directory)
   
   d->DICOMModel.setDatabase(d->DICOMDatabase->database());
   d->treeView->setModel(&d->DICOMModel);
+  d->treeView->resizeColumnToContents(0);
 
   //pass DICOM database instance to Import widget
   // d->ImportDialog->setDICOMDatabase(d->DICOMDatabase);
@@ -432,3 +435,15 @@ void ctkDICOMAppWidget::onPreviousStudy(){
         }
     }
 }
+
+//----------------------------------------------------------------------------
+void ctkDICOMAppWidget::onTreeCollapsed(const QModelIndex &index){
+    Q_D(ctkDICOMAppWidget);
+    d->treeView->resizeColumnToContents(0);
+}
+
+//----------------------------------------------------------------------------
+void ctkDICOMAppWidget::onTreeExpanded(const QModelIndex &index){
+    Q_D(ctkDICOMAppWidget);
+    d->treeView->resizeColumnToContents(0);
+}

+ 3 - 0
Libs/DICOM/Widgets/ctkDICOMAppWidget.h

@@ -70,6 +70,9 @@ protected slots:
     void onNextStudy();
     void onPreviousStudy();
 
+    void onTreeCollapsed(const QModelIndex& index);
+    void onTreeExpanded(const QModelIndex& index);
+
 private:
   Q_DECLARE_PRIVATE(ctkDICOMAppWidget);
   Q_DISABLE_COPY(ctkDICOMAppWidget);