c++ - mousePressEvent is working but mouseMoveEvent isn't -
both events work on bare mainwindow when press inside graphicsview ,placed inside mainwindow, mousepressevent responding.
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:
derive own graphics view
qgraphicsview
, implement mouse move event handler there.create event filter , install qgraphicsview's viewport (
ui->graphicsview->viewport()->installeventfilter(...)
). seeqobject::eventfilter()
documentation.
and of course, have enable mouse tracking qgraphicsview's viewport:
ui->graphicsview->viewport()->setmousetracking(true);
Comments
Post a Comment