Important: Please read the Qt Code of Conduct -

How to show a custom popup for QComboBox

  • The documentation for showPopup and hidePopup seem very unclear to me.

    The docs for showPopup say this:

    If you reimplement this function to show a custom pop-up, make sure you call hidePopup() to reset the internal state.

    Where exactly do I call QComboBox::hidePopup? Do I do it inside showPopup? That just seems a little strange to me. The docs for hidePopup tell me to call QComboBox::hidePopup in the re-implemented function which makes perfect sense. Here's my code:

    void ComboBoxWidget::showPopup() {
      // ??? QComboBox::hidePopup();
      assert(popup == nullptr);
      popup = new ComboBoxPopup{this};
    void ComboBoxWidget::hidePopup() {
      delete popup;
      popup = nullptr;

    The problem is that hidePopup is never called so my popup is never closed. I must be doing something wrong. Uncommenting that line doesn't seem to help.

  • Am I supposed to hide the popup manually? E.g. should I call hidePopup when the user clicks on an item in the popup? The popup isn't automatically hidden when the combo box loses focus so am I supposed to handle that myself too?

    I have a finished popup that looks exactly how I want it to but I'm not sure how I'm supposed to hide it. It sounds trivial but I'm really not sure.

  • The "right way" probably doesn't matter for something this trivial so I'm just calling hidePopup when the checkbox loses focus and when an item in the popup is clicked.

Log in to reply