LeaveEvent for Mouse outside of a widget
-
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?