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. How can i automatize mouse event?

How can i automatize mouse event?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 194 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.
  • D Offline
    D Offline
    deleted286
    wrote on last edited by
    #1

    Hi everyone. I have an artificial horizon. This is my mainwindow.cpp
    I want to add timer for mouse event, for example, it should turn to the right in every 20 sec. How can i do it?

    #include <cmath>
    #include <QThread>
    #include <QMouseEvent>
    #include <QDebug>
    
    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    #include "artificialhorizon.h"
    
    #define TIMEOUT (500)
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow),
        state(0),
        roll(0),
        pitch(0)
    {
        ui->setupUi(this);
        this->h = new ArtificialHorizon(this->ui->centralWidget);
        h->show();
    
        connect(&(this->timer), SIGNAL(timeout()), this, SLOT(timedOut()));
        timer.setInterval(TIMEOUT);
        timer.start();
    
    
    //    connect(this, SIGNAL(timeout()), this, SLOT(mouseMoveEvent()));
    //    timer.start(200);
    
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    void MainWindow::timedOut()
    {
        switch(state)
        {
        case 0:
            pitch += 5;
            break;
        case 1:
            pitch -= 5;
            break;
        case 2:
            pitch += 10;
            break;
        default:
            timer.stop();
            break;
        }
    
        if(state==0 && pitch>90)  //Eğer state 0sa ve pitch >90ise
        {
            state++;
            roll = 180-roll;
            pitch = 180 - pitch;
        }
        else if(state==1 && pitch < -90)
        {
            roll = 180-roll;
            pitch = -180-pitch;
            state++;
        }
        else if(state==2 && pitch > 10)
        {
            state++;
        }
    
        qDebug() << roll << "," << pitch;
        h->setRollPitch(roll,pitch);
    }
    
    void MainWindow::mouseMoveEvent(QMouseEvent *event)
    {
        int pitch = event->pos().y();
        int roll = event->pos().x();
    
        if(pitch>90)
        {
            roll = 180-roll;
            pitch = -180+pitch;
        }
        else if(pitch<-90)
        {
            roll = 180-roll;
            pitch = 180+pitch;
        }
    
        // qDebug() << event->pos().x() << "," << event->pos().y() <<  " : " << roll << "," << pitch;
    
        this->h->setRollPitch(roll, pitch);
        QMainWindow::mouseMoveEvent(event);
    }
    
    1 Reply Last reply
    0
    • sierdzioS Offline
      sierdzioS Offline
      sierdzio
      Moderators
      wrote on last edited by
      #2

      Perhaps you can use mouseMove() from QTest?

      Also, you can simply manually construct a QMouseEvent using new.

      (Z(:^

      D 1 Reply Last reply
      2
      • sierdzioS sierdzio

        Perhaps you can use mouseMove() from QTest?

        Also, you can simply manually construct a QMouseEvent using new.

        D Offline
        D Offline
        deleted286
        wrote on last edited by
        #3

        @sierdzio Thank you, i will try it

        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