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. Is it possible to use mouseMoveEvent in TableView to emit signal when mouse hover without clicking?
Forum Updated to NodeBB v4.3 + New Features

Is it possible to use mouseMoveEvent in TableView to emit signal when mouse hover without clicking?

Scheduled Pinned Locked Moved Solved General and Desktop
5 Posts 4 Posters 1.1k Views 2 Watching
  • 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
    Maxxii
    wrote on last edited by
    #1

    Hello, I'm trying to emit signal when mouse hovering rows in TableView, but I'm getting unexpected behavior when trying to debug it with qDebug(). It seems to be working, but not when mouse cursor just hovering over different rows, but only when clicking and dragging cursor while holding mouse button. Is it even possible to do what I want using mouseMoveEvent? Here's my code:
    customview.cpp:

    #include "customview.h"
    #include <QMouseEvent>
    #include <QDebug>
    
    CustomView::CustomView(QWidget *parent) : QTableView(parent)
    {
        connect(this,SIGNAL(hoverIndexChanged(const QModelIndex&)),parent,SLOT(onHoverIndexChanged(const QModelIndex&)));
    }
    
    void CustomView::mouseMoveEvent(QMouseEvent *event)
    {
        QModelIndex index = indexAt(event->pos());
        qDebug() << index;
        emit hoverIndexChanged(index);
    }
    

    mainwindow.cpp:

    MainWindow::MainWindow(QWidget *parent)    : QMainWindow(parent)    , ui(new Ui::MainWindow)
    {
    CustomView *view = new CustomView(this);
    ...
    }
    void MainWindow::onHoverIndexChanged(const QModelIndex& index)
    {
        int hoverrow = index.row();
        //qDebug() << hoverrow;
    }
    
    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Maxxii said in Is it possible to use mouseMoveEvent in TableView to emit signal when mouse hover without clicking?:

      void CustomView::mouseMoveEvent(QMouseEvent *event)

      You should call the base class here.

      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
      • Q Offline
        Q Offline
        Q139
        wrote on last edited by Q139
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          Hi
          Make sure
          https://doc.qt.io/qt-5/qwidget.html#mouseTracking-prop
          is on.

          Also are you sure its QTableView itself that gets the mouseMove and not the
          viewport ?

          1 Reply Last reply
          2
          • M Offline
            M Offline
            Maxxii
            wrote on last edited by
            #5

            @mrjj Yes, turning mouseTracking on helped indeed. Didn't know about this property. Thank you!

            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