I'm having a problem with tracking mouse movements in a QMainWindow
. I have a toggle button buttonGenerate
. Here is the code for the MainWindow
class MainWindow : public QMainWindow, private Ui::MainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
protected:
void mouseMoveEvent(QMouseEvent *);
private slots:
void on_buttonGenerate_toggled(bool checked);
};
void MainWindow::mouseMoveEvent(QMouseEvent *event)
{
label_5->setText(tr("%1 %2 %3")
.arg(event->x())
.arg(event->y())
.arg(hasMouseTracking()));
event->ignore();
}
void MainWindow::on_buttonGenerate_toggled(bool checked)
{
buttonGenerate->setText(checked
? tr("Stop")
: tr("Start"));
setMouseTracking(checked);
}
When the button is toggled on, the mouse should be tracked and its X & Y coordinates along with whether tracking is enabled or not should be shown in label_5
. When the button is toggled off, mouse tracking should be off and label_5 not-updated. This is not the case.
Regardless of whether the button is pressed, the mouse is not being tracked. Only when I hold down a mouse button will label_5
be updated, and this is irregardless of whether setMouseTracking(bool)
is active.
Any insight would be greatly appreciated.