Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Forum Updated on Feb 6th

    [Solved] QComboBox and QtWebkit

    General and Desktop
    3
    10
    2958
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • B
      brcontainer last edited by

      In Firefox/Chrome/InternetExplorer/Safari/Opera pop-ups from the combobox expand as the content, see Firefox picture:

      !http://i.stack.imgur.com/VOn9w.png(firefox combobox)!

      QComboBox pop-up does not expand the content. Pop-ups are limited by QComboBox size, see QWebView picture:

      !http://i.stack.imgur.com/dnqQA.png(QT5 qcombobox)!

      So I implemented the QComboBox::showPopup:

      @ void newQComboBox::showPopup() {
      int width = this->width();
      this->view()->setTextElideMode( Qt::ElideNone );

          const int iconSize = this->iconSize().width();
          const QFontMetrics fontMetrics = this->fontMetrics();
          const int j = this->count();
      
          for( int i=0; i < j; ++i ) {
              const int textWidth = fontMetrics.width( this->itemText(i) + "WWW" );
              if (this->itemIcon(i).isNull()) {
                  width = qMax(width, textWidth);
              } else {
                  width = qMax(width, textWidth + iconSize);
              }
          }
      
          QStyleOptionComboBox opt;
          this->initStyleOption(&opt);
          QSize size(width, 0);
          size = this->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, size, this);
      
          this->view()->setFixedWidth( width );
      
          QComboBox::showPopup();
      }@
      

      Now this will only serve a custom QComboBox.

      I would like to know if you have to modify the QComboBox::showPopup used by QtWebkit.

      QT project: https://github.com/brcontainer/qt-helper

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        if i understood you right you are looking for QComboBox::setSizeAdjustPolicy(QComboBox::AdjustToContents) ?

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • N
          NicuPopescu last edited by

          afaik to expand item view with qss you can use:

          @QComboBox QAbstractItemView
          {
          min-width:300px;
          }@

          though it would not fit the max length of one item's text; to do this you shoud handle it in code

          since the textElide is part of QStyleOption for painting with QStyle it cannot be changed by qss; so again you should set it in code ...

          1 Reply Last reply Reply Quote 0
          • B
            brcontainer last edited by

            raven-worx it did not work.

            I suppose you've mistaken, QComboBox::setSizeAdjustPolicy sets the combobox and not the pop-up (listView).

            I need to adjust the pop-up.


            NicuPopescu I try this:

            @QListView {
            min-width:400px;
            }@

            But not quite what I want, I could help?

            QT project: https://github.com/brcontainer/qt-helper

            1 Reply Last reply Reply Quote 0
            • raven-worx
              raven-worx Moderators last edited by

              ok then you can do this:
              @
              void MyComboBox::showPopup()
              {
              int width = 100; //specify minimum width
              const int iconSize = this->iconSize().width() + 4;
              const QFontMetrics fontMetrics = this->fontMetrics();

              for( int i=0; i < this->count(); ++i )
              {
                  const int textWidth = fontMetrics.width(this->itemText(i));
                  if (this->itemIcon(i).isNull())
                      width = (qMax(width, textWidth));
                  else
                      width = (qMax(width, textWidth + iconWidth));
              }
              
              QStyleOptionComboBox opt;
              this->initStyleOption(&opt);
              QSize size(width, 0);
              size = this->style()->sizeFromContents(QStyle::CT_ComboBox, &opt, size, this);
              
              this->view()->setFixedWidth( qMax(this->width(),size.width()) );
              
              QComboBox::showPopup();
              

              }
              @

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply Reply Quote 0
              • B
                brcontainer last edited by

                great solution.

                Tell me one thing in the case of webviews, it would be possible to implement something like QComboBox (the QWebView widgets uses QT itself)?

                Or will I have to modify and recompile "QT-sdk-open-source"?

                QT project: https://github.com/brcontainer/qt-helper

                1 Reply Last reply Reply Quote 0
                • raven-worx
                  raven-worx Moderators last edited by

                  AFAIK the "widgets" inside a QWebView are not drawn by Qt itself but by the webkit engine directly. For example like the scrollbars.
                  So only JS and CSS can be used to change the appearance of web elements inside a QWebView.

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply Reply Quote 0
                  • B
                    brcontainer last edited by

                    raven-worx not all elements are of webkit, in the case of combobox (pop-up) uses the QT QComboBox.

                    So much so that it is possible to style the combobox the "QWebView" used this:

                    @QComboBox{
                    ...
                    }@

                    See alternative solution: http://stackoverflow.com/a/17107731/1518921

                    But this solution is not as good as what you did. I wanted to use your code to modify the "QComboBox" the "QWebView"

                    The only solution I see is to download the source, modify the code and recompile QT-sdk.

                    Could you tell me if there is another way? Thanks!

                    QT project: https://github.com/brcontainer/qt-helper

                    1 Reply Last reply Reply Quote 0
                    • B
                      brcontainer last edited by

                      I update my question.

                      QT project: https://github.com/brcontainer/qt-helper

                      1 Reply Last reply Reply Quote 0
                      • B
                        brcontainer last edited by

                        Solution: http://stackoverflow.com/questions/20554940/qcombobox-pop-up-expanding-and-qtwebkit/20909625#20909625

                        QT project: https://github.com/brcontainer/qt-helper

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post