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. why QCombobox receive mousePressEvent when user click on other window?
QtWS25 Last Chance

why QCombobox receive mousePressEvent when user click on other window?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 284 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.
  • X Offline
    X Offline
    Xiao Yang
    wrote on last edited by
    #1

    when user click outside QCombobox, the QComboBoxPrivateContainer::mousePressEvent will be trigger, then the hidepopup() function will be call. how can i implement this behavior like qt qcombobox.cpp.
    i write a own QWidget subclass,but i dont know how to close the popup-listview when user click other space in the window.

    void QComboBoxPrivateContainer::mousePressEvent(QMouseEvent *e){
    
        QStyleOptionComboBox opt = comboStyleOption();
        opt.subControls = QStyle::SC_All;
        opt.activeSubControls = QStyle::SC_ComboBoxArrow;
        QStyle::SubControl sc = combo->style()->hitTestComplexControl(QStyle::CC_ComboBox, &opt,
                                                               combo->mapFromGlobal(e->globalPos()),
                                                               combo);
        if ((combo->isEditable() && sc == QStyle::SC_ComboBoxArrow)
            || (!combo->isEditable() && sc != QStyle::SC_None))
            setAttribute(Qt::WA_NoMouseReplay);
        combo->hidePopup();
    }
    
    1 Reply Last reply
    0
    • B Offline
      B Offline
      Bonnie
      wrote on last edited by Bonnie
      #2

      As doc says in void QWidget::mousePressEvent(QMouseEvent *event) :

      The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

      That means a popup window (Qt::Popup) will receive mousePressEvent when clicking outside it (to close it).

      X 1 Reply Last reply
      4
      • B Bonnie

        As doc says in void QWidget::mousePressEvent(QMouseEvent *event) :

        The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.

        That means a popup window (Qt::Popup) will receive mousePressEvent when clicking outside it (to close it).

        X Offline
        X Offline
        Xiao Yang
        wrote on last edited by
        #3

        @Bonnie thankyou. I need to learn about window with Qt::popup.

        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