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. LeaveEvent for Mouse outside of a widget
QtWS25 Last Chance

LeaveEvent for Mouse outside of a widget

Scheduled Pinned Locked Moved General and Desktop
leaveeventmouse
3 Posts 2 Posters 1.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.
  • R Offline
    R Offline
    RDiGuida
    wrote on last edited by
    #1

    Hello, I am trying to implement a class that outputs "IN" when the cursor is in a specific widget and "OUT" when the cursor is out. I managed to get the "IN" part but I have some problems with the LeaveEvent and it does not work. I have enabled mouse tracking on the widget of course.

    #include "my_qlabel.h"
    
    my_qlabel::my_qlabel(QWidget *parent):
                QLabel(parent)
    {
    
    }
    
    void my_qlabel::mouseMoveEvent(QMouseEvent *ev)
    {
        emit Mouse_Pos();
    }
    
    void my_qlabel::mousePressEvent(QMouseEvent *ev)
    {
        emit Mouse_Pressed();
    }
    
    void my_qlabel::leaveEvent(QMouseEvent *ev)
    {
        emit Mouse_Left();
    }
    
    

    And the main class is derived from Dialog

    #include "ui_dialog.h"
    #include "my_qlabel.h"
    
    Dialog::Dialog(QWidget *parent) :
        QDialog(parent),
        ui(new Ui::Dialog)
    {
        ui->setupUi(this);
    
        connect(ui->UpperReg,SIGNAL(Mouse_Pos()),this,SLOT(Mouse_current_pos()));
        connect(ui->UpperReg,SIGNAL(Mouse_Left()),this,SLOT(Mouse_left()));
    }
    
    Dialog::~Dialog()
    {
        delete ui;
    }
    
    void Dialog::Mouse_current_pos()
    {
        ui->Info->setText("IN");
    }
    
    void Dialog::Mouse_Pressed()
    {
    
    }
    
    void Dialog::Mouse_left()
    {
        ui->Info->setText("OUT");
    }
    

    Any ideas?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JDGXNV
      wrote on last edited by
      #2

      Are you sure you haven't mixed up capitalization of the signals and slots for Mouse_left/Mouse_Left?

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RDiGuida
        wrote on last edited by
        #3

        Yes I am sure, the one with the capital is a signal while the other is a slot

        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