[SOLVED] Mouse Tracking With GUI Builder
-
Hi, My goal is to create a simple test application where a dial will be moved by the movement of a mouse.
This is to say ONLY the movement of the mouse. I was trying something like@MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setMouseTracking(true);}@
@void MainWindow::mouseMoveEvent(QMouseEvent* )
{
ui->dial->setValue(4);
}@However it didn't seem to work. It only worked when the mouse was pressed which was not my goal.
Thank you for your help
-
You can use an event filter on the application.
Define and implement bool MainWindow::eventFilter(QObject*, QEvent*). For example..@bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::MouseMove)
{
QMouseEvent mouseEvent = static_cast<QMouseEvent>(event);
statusBar()->showMessage(QString("Mouse move (%1,%2)").arg(mouseEvent->pos().x()).arg(mouseEvent->pos().y()));
}
return false;
}
@Install the event filter when the MainWindows is constructed (or somewhere else). For example..
@MainWindow::MainWindow(...)
{
...
qApp->installEventFilter(this);
...
}
@ -
Thanks! that worked great.