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. Customizing QComboBox
Forum Updated to NodeBB v4.3 + New Features

Customizing QComboBox

Scheduled Pinned Locked Moved Solved General and Desktop
15 Posts 3 Posters 4.5k Views 2 Watching
  • 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.
  • Ivan NetskinI Ivan Netskin

    Hello, i'm trying to reimplement the behaviour of the QCombobox. I just want the popup list of the combobox be closable only by clicking on the QCombobox's button. This is done and works fine. Now the popup won't close until u click on the corresponding button.

    void CustomCbx::showPopup(){
        if(m_view->model()==NULL)
            return;
        if(m_view->model()->rowCount()==0)
            return;
        m_view->show();
        resize(width(),maxHeight);
        expanded=true;
    }
    

    But, the expanding list now won't be shown if you add this CustomCbx to layout.Any suggestions,guys? Somehow the QCombobox able to show it's items even it's within layout though. Thanks in advance!

    P.S. i'll go check the qt' sources, hope find something there.

    raven-worxR Offline
    raven-worxR Offline
    raven-worx
    Moderators
    wrote on last edited by raven-worx
    #2

    @Ivan-Netskin
    i am not quite sure what your showPopup() implementation is supposted to do.
    Is it just about resizing? Then it's enough to do this:

    void CustomCbx::showPopup()
    {
        this->view()->window()->setFixedSize( width(), maxHeight );
        QComboBox::showPopup();
        expanded=true;
    }
    

    The important part is to show the window the view is in. Means the view is placed in a popup container widget. Thus showing the view in a hidden window wont change anything.

    --- 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
    1
    • Ivan NetskinI Offline
      Ivan NetskinI Offline
      Ivan Netskin
      wrote on last edited by
      #3

      if you call QComboBox::showPopup() then the popup list will automatically will be closed if you click outside the combobox. This is why i don't call the CustomCbx::showPopup().

      raven-worxR 1 Reply Last reply
      0
      • Ivan NetskinI Ivan Netskin

        if you call QComboBox::showPopup() then the popup list will automatically will be closed if you click outside the combobox. This is why i don't call the CustomCbx::showPopup().

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #4

        @Ivan-Netskin
        even if i strongly disagree to override such a platform specific behavior, try this:

        void CustomCbx::showPopup()
        {
            this->view()->window()->setFixedSize( width(), maxHeight );
            this->view()->window()->setWindowFlags( Qt::Tool | Qt::FramelessWindowHint | Qt::CustomizeWindowHint ); // this can even be called only once in the constructor i guess
            QComboBox::showPopup();
            expanded=true;
        }
        

        --- 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

        Ivan NetskinI 1 Reply Last reply
        2
        • raven-worxR raven-worx

          @Ivan-Netskin
          even if i strongly disagree to override such a platform specific behavior, try this:

          void CustomCbx::showPopup()
          {
              this->view()->window()->setFixedSize( width(), maxHeight );
              this->view()->window()->setWindowFlags( Qt::Tool | Qt::FramelessWindowHint | Qt::CustomizeWindowHint ); // this can even be called only once in the constructor i guess
              QComboBox::showPopup();
              expanded=true;
          }
          
          Ivan NetskinI Offline
          Ivan NetskinI Offline
          Ivan Netskin
          wrote on last edited by Ivan Netskin
          #5

          @raven-worx
          Thanks, yes this helps, but side effect is that expand/collapse button stops working. i'll go to browse the qt's sources to find out the reason.

          mrjjM 1 Reply Last reply
          0
          • Ivan NetskinI Ivan Netskin

            @raven-worx
            Thanks, yes this helps, but side effect is that expand/collapse button stops working. i'll go to browse the qt's sources to find out the reason.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @Ivan-Netskin
            Hi
            bool QComboBoxPrivateContainer::eventFilter
            is stealing the mouseReleased from you.
            ( i think :)

            Ivan NetskinI 1 Reply Last reply
            0
            • mrjjM mrjj

              @Ivan-Netskin
              Hi
              bool QComboBoxPrivateContainer::eventFilter
              is stealing the mouseReleased from you.
              ( i think :)

              Ivan NetskinI Offline
              Ivan NetskinI Offline
              Ivan Netskin
              wrote on last edited by Ivan Netskin
              #7

              @mrjj
              yep , probably these lines :

              case QEvent::MouseButtonRelease: {
              	        bool ignoreEvent = maybeIgnoreMouseButtonRelease && popupTimer.elapsed() < QApplication::doubleClickInterval();
              	
              	        QMouseEvent *m = static_cast<QMouseEvent *>(e);
                      if (isVisible() && view->rect().contains(m->pos()) && view->currentIndex().isValid()
              	            && !blockMouseReleaseTimer.isActive() && !ignoreEvent
              	            && (view->currentIndex().flags() & Qt::ItemIsEnabled)
              	            && (view->currentIndex().flags() & Qt::ItemIsSelectable)) {
              	            combo->hidePopup();
              	            emit itemSelected(view->currentIndex());
              	            return true;
              	        }
              	        break;
              	    }
              
              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                yep i think so.
                But it seems you can get MouseDown so maybe u can maybe cheat and hax it that way
                and make it close.

                Ivan NetskinI 1 Reply Last reply
                1
                • mrjjM mrjj

                  yep i think so.
                  But it seems you can get MouseDown so maybe u can maybe cheat and hax it that way
                  and make it close.

                  Ivan NetskinI Offline
                  Ivan NetskinI Offline
                  Ivan Netskin
                  wrote on last edited by
                  #9

                  customizing qcombobox is a bit pain. Changing little option may result in
                  an unexpected behaviour of the enitre combobox. Is there a way to get expandable list, even if the list inside layout?

                  mrjjM 1 Reply Last reply
                  0
                  • Ivan NetskinI Ivan Netskin

                    customizing qcombobox is a bit pain. Changing little option may result in
                    an unexpected behaviour of the enitre combobox. Is there a way to get expandable list, even if the list inside layout?

                    mrjjM Offline
                    mrjjM Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on last edited by
                    #10

                    @Ivan-Netskin
                    Well you are fiddling with the core logic. That often leads to side effects.

                    Qt is using private classes to increase compatibility but it also often kills
                    true reuse as only the virtual function the developers could imagine are
                    there to override. But it's worth it :)

                    Also note, you can chain event filters so you might be able that way.

                    However, if you only need combobox then QListWidget and QPushbutton could
                    be use to make fake one. If you need the edit part it becomes more complicated.
                    set Min/max and fixed size are still allowed in layouts.

                    1 Reply Last reply
                    1
                    • Ivan NetskinI Offline
                      Ivan NetskinI Offline
                      Ivan Netskin
                      wrote on last edited by Ivan Netskin
                      #11

                      thanks for reply, the problem is that if i change the widget size,which lies in layout - it will result in growing size of the whole application. This is undesirable behaviour in my case. Also just creating a listview widget without parent and moving it under the QCombobox looks like unclean solution a bit.

                      mrjjM 1 Reply Last reply
                      0
                      • Ivan NetskinI Ivan Netskin

                        thanks for reply, the problem is that if i change the widget size,which lies in layout - it will result in growing size of the whole application. This is undesirable behaviour in my case. Also just creating a listview widget without parent and moving it under the QCombobox looks like unclean solution a bit.

                        mrjjM Offline
                        mrjjM Offline
                        mrjj
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @Ivan-Netskin
                        ok. it must be floating then :)
                        Before giving up on your custom combobox I would have a look at the eventfilter docs.
                        You might be able to put yourself in front and control it that way.

                        1 Reply Last reply
                        0
                        • Ivan NetskinI Offline
                          Ivan NetskinI Offline
                          Ivan Netskin
                          wrote on last edited by
                          #13

                          found something appropriate - http://libqxt.bitbucket.org/doc/tip/qxtcheckcombobox.html

                          mrjjM 1 Reply Last reply
                          0
                          • Ivan NetskinI Ivan Netskin

                            found something appropriate - http://libqxt.bitbucket.org/doc/tip/qxtcheckcombobox.html

                            mrjjM Offline
                            mrjjM Offline
                            mrjj
                            Lifetime Qt Champion
                            wrote on last edited by
                            #14

                            @Ivan-Netskin
                            But will it stay open ?

                            1 Reply Last reply
                            0
                            • Ivan NetskinI Offline
                              Ivan NetskinI Offline
                              Ivan Netskin
                              wrote on last edited by Ivan Netskin
                              #15

                              From discription it's allowing to select multiple items - that's good enough

                              1 Reply Last reply
                              1

                              • Login

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