Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Mouse Tracking With GUI Builder
QtWS25 Last Chance

[SOLVED] Mouse Tracking With GUI Builder

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 4.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrstarware
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • S Offline
      S Offline
      shoyeb
      wrote on last edited by
      #2

      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);
      ...
      }
      @

      There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mrstarware
        wrote on last edited by
        #3

        Thanks! that worked great.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          shoyeb
          wrote on last edited by
          #4

          please mark ur thread as solved...

          There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Aj Ay
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Aj Ay
              wrote on last edited by
              #6

              Hai shoyeb,

              Can you help me in my requirement of displaying world map and co-ordinates on map with mouse movements

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved