nilot
10th April 2017, 09:52
Hello,
In a QDialog, I would like to display the mouse coordinates when the mouse is above a widget which is included in the QDialog.
Using "setMouseTracking", it works when the widget is a QLabel but it doesn't when it is a QGraphicsView : if the mouse moved above the qgraphicsview, the function mouseMoveEvent of the QDialog isn't called. Why ?
Example:
#include <QDialog>
#include <QGridLayout>
#include <QDebug>
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QLabel>
class MyDialog : public QDialog
{
public:
MyDialog() : QDialog()
{setMouseTracking(true);}
protected:
void mouseMoveEvent(QMouseEvent *event)
{
qDebug()<<QCursor::pos();
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
MyDialog dlg;
QGridLayout *l = new QGridLayout(&dlg);
QLabel* label1 = new QLabel("Above Label");
label1->setMouseTracking(true);
QGraphicsScene* scene = new QGraphicsScene(0, 0, 100, 100);
QGraphicsView* view = new QGraphicsView(scene);
view->setMouseTracking(true);
l->addWidget(label1,0, 0);
l->addWidget(view, 0, 1, 2, 1);
return dlg.exec();
}
Thank you.
In a QDialog, I would like to display the mouse coordinates when the mouse is above a widget which is included in the QDialog.
Using "setMouseTracking", it works when the widget is a QLabel but it doesn't when it is a QGraphicsView : if the mouse moved above the qgraphicsview, the function mouseMoveEvent of the QDialog isn't called. Why ?
Example:
#include <QDialog>
#include <QGridLayout>
#include <QDebug>
#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QLabel>
class MyDialog : public QDialog
{
public:
MyDialog() : QDialog()
{setMouseTracking(true);}
protected:
void mouseMoveEvent(QMouseEvent *event)
{
qDebug()<<QCursor::pos();
}
};
int main(int argc, char **argv){
QApplication app(argc, argv);
MyDialog dlg;
QGridLayout *l = new QGridLayout(&dlg);
QLabel* label1 = new QLabel("Above Label");
label1->setMouseTracking(true);
QGraphicsScene* scene = new QGraphicsScene(0, 0, 100, 100);
QGraphicsView* view = new QGraphicsView(scene);
view->setMouseTracking(true);
l->addWidget(label1,0, 0);
l->addWidget(view, 0, 1, 2, 1);
return dlg.exec();
}
Thank you.