Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] QComboBox and QtWebkit
QtWS25 Last Chance

[Solved] QComboBox and QtWebkit

Scheduled Pinned Locked Moved General and Desktop
10 Posts 3 Posters 3.4k Views
  • 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 Offline
    B Offline
    brcontainer
    wrote on 12 Dec 2013, 21:49 last edited by
    #1

    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
    0
    • R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 13 Dec 2013, 07:56 last edited by
      #2

      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
      0
      • N Offline
        N Offline
        NicuPopescu
        wrote on 13 Dec 2013, 11:04 last edited by
        #3

        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
        0
        • B Offline
          B Offline
          brcontainer
          wrote on 13 Dec 2013, 14:49 last edited by
          #4

          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
          0
          • R Offline
            R Offline
            raven-worx
            Moderators
            wrote on 13 Dec 2013, 15:26 last edited by
            #5

            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
            0
            • B Offline
              B Offline
              brcontainer
              wrote on 13 Dec 2013, 16:15 last edited by
              #6

              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
              0
              • R Offline
                R Offline
                raven-worx
                Moderators
                wrote on 16 Dec 2013, 07:25 last edited by
                #7

                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
                0
                • B Offline
                  B Offline
                  brcontainer
                  wrote on 16 Dec 2013, 15:45 last edited by
                  #8

                  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
                  0
                  • B Offline
                    B Offline
                    brcontainer
                    wrote on 20 Dec 2013, 21:27 last edited by
                    #9

                    I update my question.

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

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      brcontainer
                      wrote on 3 Jan 2014, 17:56 last edited by
                      #10

                      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
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved