Get coordinates of dicom image by clicking anywhere on image in Qt
-
Hello,
I am making GUI application in Qt where I want load my Dicom images in QWidget box.
And I need to get actual XYZ coordinates of dicom images on screen by clicking anywhere on the image. And then use those for further processing.
Can anyone please tell me how to create function of QT to click on an image and get the actual coordinates of dicom image (which are pixels has range from 256256 or 512512)?Thanks in advance.
-
Hi and welcome to devnet,
All Qt widgets have the mousePressEvent method. You can use that in the widget that show the image to know where you are.
Note that there's already the QtDcm project that seems to provide everything needed.
Maybe the MITK project could also be of interest.
-
@SGaist Hello,
Thank you for your reply.
With mousepressevent, can i get coordinates also?
And Could you please provide me some examples for mousepressevent with QWidget?
I don't know how to write code for it to get coordinates of dicom image.
I think seeing example can help me to understand how to use mousepressevent.Thanks again.
-
@pvirk said in Get coordinates of dicom image by clicking anywhere on image in Qt:
With mousepressevent, can i get coordinates also?
Yes, https://doc.qt.io/qt-5/qmouseevent.html#pos
Example: https://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html -
@pvirk said in Get coordinates of dicom image by clicking anywhere on image in Qt:
XYZ coordinates of dicom images
Just to be clear. the mousepressevent gives your the x,y in pixels.
There is no Z. -
@jsulm Thank you.
I have tried the example from
https://www.youtube.com/watch?v=5dI0u84VGoY here.
It gives me x,y coordinates wherever I double-click on Qt window.But if I put QWidget (specifically I want to use QVTKWidget where I will get my dicom images) in .ui file, then I don't understand what to change in above example, to get x, y coordinates only in that particular QWidget/QVTKWidget window (not outside of it). And then save it so I can use it for further processing.
Could you please tell me in details?Thanks a lot again.
-
@pvirk Subclass QVTKWidget, override mousePressEvent() in your subclass and use that one instead of QVTKWidget
https://vtk.org/doc/nightly/html/classQVTKWidget.html#aa92a6e9081f134c41ef985a44d7e90a6 -
@pvirk said in Get coordinates of dicom image by clicking anywhere on image in Qt:
I am new to Qt
It's actually C++
class MyWidget : public QVTKWidget { protected: void QVTKWidget::mousePressEvent(QMouseEvent * event) ; }
And now use this MyWidget class instead of QVTKWidget.
-
You are just mixing unrelated stuff.
@jsulm provided you with the minimal class definition to get started.
If you don't know how to do subclassing, then please, start by going through basic C++ tutorials before going further. You'll save yourself a lot of trouble.
-
Hello,
I have tried example to understand mousepressevent in QWidget.
But I am facing some problem, when I use it in my code.
I used one QVTKWidget to check coordinates with mousepressevent, and it worked. But when I use that same QVTKWIdget to load dicom data using vtkRenderWindow and interactor, it shows following errors. Here "matDisplay" is class I created for mousepressevent.- Error C2039 'SetRenderWindow': is not a member of 'matDisplay'
- Error C2039 'GetInteractor': is not a member of 'matDisplay'
I need Render Window and Interactor to render dicom images.
So, how can I use mousepressevent in QVTKWidget?
Please help and thanks in advance.
-
What is
matDisplay
? -
Hi
Can you show your exact code for matDisplay ?It should have those functions
https://github.com/Kitware/VTK/blob/master/GUISupport/Qt/QVTKWidget.h -
Hello,
'matDisplay' is class i created for mousepressevent.
then I used
QObject::connect(ui->qvtkWidget_3, SIGNAL(sendMousePosition(QPoint&)), this, SLOT(showMousePosition(QPoint&))); in my other .cpp file.This thing works. Here I used subclass QWidget. But if I use QVTKWidget subclass, then build succeeded but then my program crashes.
But when I used this qvtkwidget_3 to get my dicom data, then shows me those errors.
Anyone has any idea about it? -
@pvirk
Hi
It has to inherit from QVTKWidget
as else it wont be right for the other classes as the errors shows:Error C2039 'SetRenderWindow': is not a member of 'matDisplay'
Error C2039 'GetInteractor': is not a member of 'matDisplay'This is correct as a QWidget does not have them. It comes from
QVTKWidget.You have to use that QVTKWidget find out why it crashes.
I would guess you might forgot
to call
: QVTKWidget(parent) and maybe had QWidget(parent) from before.
so that the QVTKWidget was not ok setup. = crash -
Hello,
I changed it to :QVTKWidget in both my .h and .cpp files of matDisplay class.
The reason for crashing was, In .ui file the qvtkwidget was not promoted to QVTKWidget.h file. I promoted to it and now there is no crashing.
But now the problem is I cannot use my matDisplay.h also as promoted class in .ui file. Because of that I cannot get coordinates of that widget.
How can I use both my QVTKWidget.h and matDisplay.h as promoted classes for qvtkwidget in .ui file?
I double-checked both of them in promoted widget option, but still it is only promoted to qvtkwidget.h only?