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 detect mouse click outside of widget?

How to detect mouse click outside of widget?

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

    I've created a modal QDialog which shows a single QLineEdit. I'm using it to allow the user to change the name of a data object. I'd like to automatcially close my dialog with a call to reject() if the user ever clicks outside of the dialog area. I've added a mousePressEvent() to my dialog's class, but it never gets called.

    Is there a way for me to tell if the user clicks away from my dialog box?

    raven-worxR 1 Reply Last reply
    0
    • K kitfox

      I've created a modal QDialog which shows a single QLineEdit. I'm using it to allow the user to change the name of a data object. I'd like to automatcially close my dialog with a call to reject() if the user ever clicks outside of the dialog area. I've added a mousePressEvent() to my dialog's class, but it never gets called.

      Is there a way for me to tell if the user clicks away from my dialog box?

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

      @kitfox said in How to detect mouse click outside of widget?:

      Is there a way for me to tell if the user clicks away from my dialog box?

      either listen to a QEvent::WindowDeactivate event or use qApp->installEventFilter(filter) and listen for mouse press events

      --- 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
      2
      • A Offline
        A Offline
        Asperamanca
        wrote on last edited by
        #3

        Alternatively, you can use grabMouse() to receive mouse events. However, that will cause the first click outside your dialog (the one where you close the dialog) to be eaten up.

        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