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 I can find out which widget particular was clicked?

How I can find out which widget particular was clicked?

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 5.6k 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.
  • I Offline
    I Offline
    isaacEnrique
    wrote on last edited by
    #1

    Greetings .

    I want to know as within of:

    @
    MyCustomWidget::mousePressEvent(QMouseEvent*)
    MyCustomWidget::mouseReleaseEvent(QMouseEvent*)
    MyCustomWidget::mouseMoveEvent(QMouseEvent*)
    @

    How I can know on which widget the mouse event was generated? .

    I understand a mouse event occurs when one or more mouse buttons are pressed or released inside a widget or when the mouse is moved .

    I am creating a custom widget (using QWidget as the base class) which has several elements: an area that shows a picture (with a QScrollArea and QLabel) and an area with several checks (2 QPushButton, 1 QCheckBox, 1 QToolButton, ect) . I want to allow the user to highlight regions with the mouse on the image (drawing rectangles) , for this I am reimplementing the functions I wrote above.

    The problem is that I only need do this when mouse events occur over the area shown in the image. So, my specific question is with QMouseEvent :

    How I can find out which widget particular was clicked?

    Formulating the question would be more generally:
    When you have a complex custom widget (with several child widgets), How I can find out about which widget particular (from the children widgtes) mouse event has occurred?

    Thanks in advance for any help and/or suggestion.

    Isaac Pérez
    Programming is understanding.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      cosmam
      wrote on last edited by
      #2

      Given the position from the mouse event, you should be able to use "a QWidget function called childAt":http://qt-project.org/doc/qt-5/qwidget.html#childAt-2 to get the child at that location.

      The downside is that it returns only a single child, so if you've got a stack of children there, this will only give you the top-most (I believe).

      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