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. Get Mouse Event to Function: Resolved
Forum Updated to NodeBB v4.3 + New Features

Get Mouse Event to Function: Resolved

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 3 Posters 378 Views 1 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.
  • B Offline
    B Offline
    BKBK
    wrote on last edited by BKBK
    #1

    Linux Centos, C++
    I need help with a basic concept: How is a mouse event routed/directed to a function? The h file contains

    #include <qevent.h>
    void mouse_click_event( QMouseEvent * event );
    

    The dot cpp file contains

    Void C_Strip_Chart::mouse_click_event( QMouseEvent * event )
    { printf( “mouse event” ); }
    

    The printf is never called. The part I have not recognized is: What routes the mouse event to the function?
    Thank you for your time.

    J.HilkJ 1 Reply Last reply
    0
    • Kent-DorfmanK Online
      Kent-DorfmanK Online
      Kent-Dorfman
      wrote on last edited by Kent-Dorfman
      #2

      What is C_Strip_Chart derived from? Classes need to be derived from the QObject base to register events. Also, events are a lower level than signal/slot mechanism.

      You normally connect a widget's clicked() signal to a target slot that gets executed when the mouse is clicked on the widget....OH, and the base class QWidget can handle the mouse events through its protected virtuals.

      Events involve overriding protected virtuals that exist in the class, thus the reason for deriving from QObject.

      I light my way forward with the fires of all the bridges I've burned behind me.

      1 Reply Last reply
      4
      • B BKBK

        Linux Centos, C++
        I need help with a basic concept: How is a mouse event routed/directed to a function? The h file contains

        #include <qevent.h>
        void mouse_click_event( QMouseEvent * event );
        

        The dot cpp file contains

        Void C_Strip_Chart::mouse_click_event( QMouseEvent * event )
        { printf( “mouse event” ); }
        

        The printf is never called. The part I have not recognized is: What routes the mouse event to the function?
        Thank you for your time.

        J.HilkJ Offline
        J.HilkJ Offline
        J.Hilk
        Moderators
        wrote on last edited by
        #3

        @BKBK what's supposed to call mouse_click_event ? because even if QWidget is the base class, the is no orverrideable function with that name


        Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


        Q: What's that?
        A: It's blue light.
        Q: What does it do?
        A: It turns blue.

        1 Reply Last reply
        3
        • B Offline
          B Offline
          BKBK
          wrote on last edited by
          #4

          C_Strip_Chart is the main and top level widget. It inherits from QWidget.
          What's supposed to call mouse_click_event? Both replies prompted me to think along the correct path. Changed mouse_click_event to mousePressEvent(...) and it started working.
          Not only that, I understand what I was doing wrong and why.

          Thank you both for your time and patience.

          1 Reply Last reply
          1
          • Kent-DorfmanK Online
            Kent-DorfmanK Online
            Kent-Dorfman
            wrote on last edited by
            #5

            If C_Strip_Chart is derived from QWidget then simply overriding any of the protected virtuals should cause them to be executed. Use the docs, Luke. the QWidget page adequately shows all the relevant methods.

            I light my way forward with the fires of all the bridges I've burned behind me.

            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