Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-10477

QComboBox: QComboMenuDelegate used in Editable+QCleanLooksStyle doesn't calculate the sizeHint basing on the content of the drop down list

    XMLWordPrintable

Details

    Description

      With setEditable(true) and QCleanLooksStyle, QComboBox uses QComboMenuDelegate for the drop down list, which doesn't calculate the sizeHint basing on the content.
      In the below example you can see that:
      int viewWidth = view ()->sizeHintForColumn (0);
      The value returned by sizeHintForColumn is very small since the delegate doesn't calculate the column size.

      test case to reproduce the problem:

      #include <QtGui>
      class MyComboBox : public QComboBox
      {
      public:
              MyComboBox (QWidget* parent):QComboBox(parent){};
              virtual void showPopup ();
      };
      
      
      void MyComboBox::showPopup ()
      {
              if (model () && view ())
              {
                      QWidget* qw = dynamic_cast<QWidget*> (view ()->parent ());
                      if (qw) {
                              int myWidth = size ().width ();
                              int viewWidth = view ()->sizeHintForColumn (0);
                              qWarning() << "sizehint for column:" << viewWidth << myWidth;
      
                              if (count() > maxVisibleItems ()) {
                                      viewWidth += style()->pixelMetric (QStyle::PM_ScrollBarExtent);
                              }
                              int maxWidth = qMax (qMin (viewWidth, 500) + 5, myWidth);
                              qWarning() << maxWidth;
                              qw->setFixedWidth (maxWidth);
                      }
              }
              QComboBox::showPopup();
      }
      
      int main(int argc, char** argv)
      {
              QApplication app (argc, argv);
              app.setStyle (new QCleanlooksStyle); // bud case
              //app.setStyle (new QPlastiqueStyle); // good case
      
              MyComboBox* comboBox = new MyComboBox (NULL);
              comboBox->setEditable (true);
              comboBox->addItem ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
              comboBox->addItem ("BBBBBBBBBBBBBBBBBBBBBBBBBBBB");
              qWarning() << qApp->style();
              comboBox->show();
              app.exec();
      }
      
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            bachewii Jens
            sanonymous Nokia Qt Support (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes