This is working as well!!! Thanks
Added after 6 minutes:
Thanks a lot. The gray value is working!!!
However for the "mouseMoveEvent" of the QGraphicsItem I am not very sure how to implement it. I am still very new in Qt. I have tried the following code but failed. It give me the following error messages
1.) E:\SelfLearning\3D_GUI\ViewZoomIn\mainwindow.cpp:3 2: error: C2027: use of undefined type 'QGraphicsSceneMouseEvent')
2.) E:\SelfLearning\3D_GUI\ViewZoomIn\mainwindow.cpp:3 2: error: C2227: left of '->globalPos' must point to class/struct/union/generic type
My code in mainwindow.h
snippet of code in mainwindow.cpp#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
#include <QGraphicsScene>
#include <QGraphicsItem>
#include <QGraphicsView>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void on_pushButton_clicked();
protected:
//void mousePressEvent(QMouseEvent * event);
void mouseMoveEvent(QGraphicsSceneMouseEvent * event);
private:
Ui::MainWindow *ui;
QGraphicsScene* scene;
QGraphicsItem* item;
QPixmap pix;
};
#endif // MAINWINDOW_H
void MainWindow::mouseMoveEvent(QGraphicsSceneMouseEven t *event)
{
// QGraphicsItem::mouseMoveEvent(event);
QPoint local_pt = ui->graphicsView->mapFromGlobal(event->globalPos());
QPointF img_coord_pt = ui->graphicsView->mapToScene(local_pt);
double x = img_coord_pt.x();
double y = img_coord_pt.y();
/* How can I get a gray level image here */
QRgb rgbValue = pix.toImage().pixel(x,y);
int greyvalue = qGray(rgbValue);
ui->label_X->setText(QString::number(x));
ui->label_Y->setText(QString::number(y));
ui->label_Value->setText(QString::number(greyvalue));
}
Bookmarks