c++ - mousePressEvent is working but mouseMoveEvent isn't -


both events work on bare mainwindow when press inside graphicsview ,placed inside mainwindow, mousepressevent responding. enter image description here

could clarify issue?

upd: here code

#include "mainwindow.h" #include "ui_mainwindow.h" #include "mydialog.h" #include <qdebug>  mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     ui->setupui(this);     scene = new qgraphicsscene(this);     ui->graphicsview->setscene(scene);      pix = new qpixmap("/users/mac/pictures/wallpaper/rocks.jpg");     scene->addpixmap(*pix); }  mainwindow::~mainwindow() {     delete ui; }  void mainwindow::mousepressevent(qmouseevent *e) {     sel_reg_beg_x = e->x();     sel_reg_beg_y = e->y();     qdebug() << "inside press"; }  void mainwindow::mousemoveevent(qmouseevent *e) {     qdebug() << "inside move";     sel_reg_end_x = e->x();     sel_reg_end_y = e->y();     this->update();  } 

you have 2 options here:

  1. derive own graphics view qgraphicsview , implement mouse move event handler there.

  2. create event filter , install qgraphicsview's viewport (ui->graphicsview->viewport()->installeventfilter(...)). see qobject::eventfilter() documentation.

and of course, have enable mouse tracking qgraphicsview's viewport:

ui->graphicsview->viewport()->setmousetracking(true); 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -