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. mouseEvent->pos().x() always return 0. mouseEvent->pos().y() updating on mouse move
Forum Updated to NodeBB v4.3 + New Features

mouseEvent->pos().x() always return 0. mouseEvent->pos().y() updating on mouse move

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

    mouseEvent->pos().x() always return 0. mouseEvent->pos().y() updating on mouse move

    
    bool Module3::eventFilter(QObject *obj, QEvent *event) { 
    
           QMouseEvent *mouseEvent = static_cast(event);
         
          if(obj ==scene && event->type() == QEvent::GraphicsSceneMouseMove){
      
            QToolTip::showText(mouseEvent->pos(),QString::number(
                   mouseEvent->pos().x()) + ", " + QString::number( 
                   mouseEvent->pos().y()));
          }
    
           return false;
    }```
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Since you check for GraphicsSceneMouseMove I would guess it's a QGraphicsSceneMouseEvent, not a QMouseEvent.

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      1
      • S Offline
        S Offline
        sujith D
        wrote on last edited by
        #3

        updated code qInfo() working but QToolTip shows eroor error: no matching function for call to ‘QToolTip::showText(QPointF, const QString).

        bool Module3::eventFilter(QObject *obj, QEvent *event)
        {
         
        
            if (obj == scene && event->type() == QEvent::GraphicsSceneMouseMove) {
            
                 if (auto *mouseEvent = dynamic_cast<QGraphicsSceneMouseEvent*>(event)) {
                  qInfo()<<"x"<<mouseEvent->scenePos().x()<<"y"
                    <<mouseEvent->scenePos().y();
        
                           QToolTip::showText(mouseEvent->scenePos(),
                                QString::number(
                                mouseEvent->scenePos().x()) +
                             ", "  + QString::number( 
                               mouseEvent->scenePos().y())); 
        
        
                }
             }
          }
        
        
        
        1 Reply Last reply
        0
        • Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Because, as the compiler complains - QToolTip::showText() needs a QPoint instead a QPointF - so you have to convert it.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          1 Reply Last reply
          1
          • S Offline
            S Offline
            sujith D
            wrote on last edited by
            #5

            This code works

            bool Module3::eventFilter(QObject *obj, QEvent *event)
            {
             
                if (obj == scene && event->type() == QEvent::GraphicsSceneMouseMove) {
                        if (auto *mouseEvent = 
                                   dynamic_cast<QGraphicsSceneMouseEvent *>(event)) {
                                   QToolTip::showText(
                                   mouseEvent->scenePos().toPoint(),QString::number(
                                   mouseEvent->scenePos().x()) +  ", "  + 
                                   QString::number( mouseEvent->scenePos().y()));
                    }
                }
            
            
              return false;
            }
            
            Christian EhrlicherC 1 Reply Last reply
            0
            • S sujith D

              This code works

              bool Module3::eventFilter(QObject *obj, QEvent *event)
              {
               
                  if (obj == scene && event->type() == QEvent::GraphicsSceneMouseMove) {
                          if (auto *mouseEvent = 
                                     dynamic_cast<QGraphicsSceneMouseEvent *>(event)) {
                                     QToolTip::showText(
                                     mouseEvent->scenePos().toPoint(),QString::number(
                                     mouseEvent->scenePos().x()) +  ", "  + 
                                     QString::number( mouseEvent->scenePos().y()));
                      }
                  }
              
              
                return false;
              }
              
              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @sujith-D Then please mark this topic as solved, thx

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              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