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. mouse move and mouse release events don't respond
Forum Update on Monday, May 27th 2025

mouse move and mouse release events don't respond

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

    Hello, QT! I am a begginer in QT and I wanted to drag the scene with mouse move event, but i faced some troubles. I don't really understand, what should I do.

    Part of .cpp code

    void Widget::mousePressEvent(QMouseEvent* event)
    {
        if (event->button() == Qt::MiddleButton)
        {
            QApplication::setOverrideCursor(Qt::SizeAllCursor);
            midMousePressed = true;
            m_originX = event->x();
            m_originY = event->y();
            event->accept();
            return;
        }
    }
    
    void Widget::mouseReleaseEvent(QMouseEvent *event){
        if (event->button() == Qt::MiddleButton)
        {
            midMousePressed = false;
            QApplication::restoreOverrideCursor();
            event->accept();
            return;
        }
        event->ignore();
    }
    
    void Widget::mouseMoveEvent(QMouseEvent* event)
    {
        if (midMousePressed == true)
        {
            QPointF oldp = ui->graphicsView->mapToScene(m_originX, m_originY);
            QPointF newp = ui->graphicsView->mapToScene(event->pos());
            QPointF translation = newp - oldp;
            ui->graphicsView->translate(translation.x(), translation.y());
            m_originX = event->x();
            m_originY = event->y();
            event->accept();
            return;
        }
        event->ignore();
    }
    

    Working in QT 5.15.2

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      You should rather do that at the view level.

      See here for a possible implementation.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      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