Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

mouseMoveEvent works only if mouse is clicking



  • Hi,
    i'm trying to use mouseMoveEvent function in order to tracking the position of the mouse. But it works only if i hold the mouse button. I need it works always.
    Thank you

    MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
    {

    ui->setupUi(this);
    setMouseTracking(true);
    

    }

    MainWindow::~MainWindow()
    {
    delete ui;
    }

    void MainWindow::mouseMoveEvent(QMouseEvent *event){

    QPoint pos=mapFromGlobal(QCursor::pos());
    qDebug() << pos << endl;
    if(QWidget::childAt(pos.x(),pos.y())) ui->INFO->setText(QWidget::childAt(pos.x(),pos.y() )->whatsThis());
    else ui->INFO->clear();
    

    }


  • Lifetime Qt Champion

    Hi,

    You are not calling the base class implementation nor are you handling the event itself so it gets lost.


Log in to reply