Browse Source

Don't allow ctkMenuComboBox to have a size smaller than size hint

ctkMenuComboBox::QComboBox::sizeHint is the right size to display
the characters, the icon and the popup arrow.
Resizing ctkMenuComboBox to a width smaller would truncate the display.
Don't allow that.
Julien Finet 14 years ago
parent
commit
632f760cc2
2 changed files with 14 additions and 2 deletions
  1. 13 2
      Libs/Widgets/ctkMenuComboBox.cpp
  2. 1 0
      Libs/Widgets/ctkMenuComboBox_p.h

+ 13 - 2
Libs/Widgets/ctkMenuComboBox.cpp

@@ -56,6 +56,14 @@ void ctkMenuComboBoxInternal::showPopup()
 }
 
 // -------------------------------------------------------------------------
+QSize ctkMenuComboBoxInternal::minimumSizeHint()const
+{
+  // Cached QComboBox::minimumSizeHint is not recomputed when the current
+  // index change, however QComboBox::sizeHint is. Use it instead.
+  return this->sizeHint();
+}
+
+// -------------------------------------------------------------------------
 ctkMenuComboBoxPrivate::ctkMenuComboBoxPrivate(ctkMenuComboBox& object)
   :q_ptr(&object)
 {
@@ -84,8 +92,11 @@ void ctkMenuComboBoxPrivate::init()
   this->SearchCompleter = new QCompleter(QStringList(), q);
   this->SearchCompleter->setCaseSensitivity(Qt::CaseInsensitive);
 
-  //q->setSizePolicy(this->MenuComboBox->sizePolicy());
-  q->setSizePolicy(QSizePolicy::MinimumExpanding, QSizePolicy::Fixed);
+  // Automatically set the minimumSizeHint of the layout to the widget
+  layout->setSizeConstraint(QLayout::SetMinimumSize);
+  // Behave like a QComboBox
+  q->setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed,
+                               QSizePolicy::ComboBox));
   q->setDefaultText(ctkMenuComboBox::tr("Search..."));
 }
 

+ 1 - 0
Libs/Widgets/ctkMenuComboBox_p.h

@@ -38,6 +38,7 @@ public:
   virtual ~ctkMenuComboBoxInternal();
   virtual void showPopup();
 
+  virtual QSize minimumSizeHint()const;
   QWeakPointer<QMenu>  Menu;
 };