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. How to show a custom popup for QComboBox

How to show a custom popup for QComboBox

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 1 Posters 1.3k 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.
  • K Offline
    K Offline
    Kerndog73
    wrote on last edited by
    #1

    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() {
      QComboBox::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.

    1 Reply Last reply
    0
    • K Offline
      K Offline
      Kerndog73
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • K Offline
        K Offline
        Kerndog73
        wrote on last edited by
        #3

        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.

        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