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 notify a widget for mouse event?
Forum Updated to NodeBB v4.3 + New Features

How to notify a widget for mouse event?

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

    hi,
    i want to create a class that when i bring my mouse to a widget(e.g. qPushButton or qLabel etc.) its color changes or its text becomes bold…
    please help me how can i do that?
    tnx :)

    1 Reply Last reply
    0
    • M Offline
      M Offline
      MuldeR
      wrote on last edited by
      #2

      To enable mouse tracking:
      [quote]mouseTracking : bool

      This property holds whether mouse tracking is enabled for the widget.

      If mouse tracking is disabled (the default), the widget only receives mouse move events when at least one mouse button is pressed while the mouse is being moved.

      If mouse tracking is enabled, the widget receives mouse move events even if no buttons are pressed.[/quote]

      Then you can simply re-implement QWidget::mouseMoveEvent() in your widget to process the events - or you install an event filter on the widget object (the latter is when you don't want to sub-class).

      My OpenSource software at: http://muldersoft.com/

      Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

      Go visit the coop: http://youtu.be/Jay...

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mohamaddanesh44
        wrote on last edited by
        #3

        i wanna create a class to do that. could you help me in that?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          MuldeR
          wrote on last edited by
          #4

          @class MyWidget : public QLabel
          {
          MyWidget ( QWidget * parent = 0)
          :
          QLabel(parent)
          {
          setMouseTracking(true);
          }
          virtual void mouseMoveEvent ( QMouseEvent * event )
          {
          qDebug("Mouse has been moved!");
          }
          virtual void enterEvent ( QEvent * event )
          {
          qDebug("Mouse cursor has entered!");
          }
          virtual void leaveEvent ( QEvent * event )
          {
          qDebug("Mouse cursor has left!");
          }
          }@

          My OpenSource software at: http://muldersoft.com/

          Qt v4.8.6 MSVC 2013, static/shared: http://goo.gl/BXqhrS

          Go visit the coop: http://youtu.be/Jay...

          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