[SOLVED] Mouse Tracking With GUI Builder
-
wrote on 22 Feb 2012, 18:55 last edited by
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
-
wrote on 23 Feb 2012, 04:30 last edited by
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);
...
}
@ -
wrote on 23 Feb 2012, 05:18 last edited by
Thanks! that worked great.
-
wrote on 23 Feb 2012, 06:02 last edited by
please mark ur thread as solved...
-
wrote on 29 Dec 2013, 18:52 last edited by
Hai mrstarware,
Can you please post your complete code of mouse movements because my requirement is similar one i.e to display co-ordinates on world map with movement of mouse on map.
-
wrote on 29 Dec 2013, 18:56 last edited by
Hai shoyeb,
Can you help me in my requirement of displaying world map and co-ordinates on map with mouse movements