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

How to detect mouse click outside of widget?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 3 Posters 3.3k 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 5 Dec 2018, 20:14 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?

    R 1 Reply Last reply 5 Dec 2018, 20:42
    0
    • K kitfox
      5 Dec 2018, 20:14

      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?

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 5 Dec 2018, 20:42 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 6 Dec 2018, 08:01 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

        2/3

        5 Dec 2018, 20:42

        • Login

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