C++ (Qt)#ifndef WIDGET_H#define WIDGET_H #include <QWidget>#include <QLabel>#include <QFormLayout>#include <QMouseEvent> class Widget : public QWidget{ Q_OBJECT public: Widget(QWidget *parent = 0) : QWidget() { QFormLayout* layout = new QFormLayout(); layout->addRow("Global: ", &labelGlobal); layout->addRow("Local: ", &labelLocal); setLayout(layout); setMouseTracking(true); } private: QLabel labelGlobal; QLabel labelLocal; protected: void mouseMoveEvent(QMouseEvent* event) { QPoint pos = event->pos(); labelLocal.setText(QString("%1x%2").arg(pos.x()).arg(pos.y())); pos = mapToGlobal(pos); labelGlobal.setText(QString("%1x%2").arg(pos.x()).arg(pos.y())); QWidget::mouseMoveEvent(event); }}; #endif // WIDGET_H