Get coordinates of dicom image by clicking anywhere on image in Qt
-
@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?
-
HI
you can not promote a widget to 2 different widgets.
That is not possible but would be cool if it could work :)
You can have 2 widgets but im not sure why you want that.From the code, matDisplay is your version of QVTKWidget so
you should place a QWidget and promote that to matDisplay.And it then contains your extra code for mousePress and all of QVTKWidget
-
I tried this way.
I used QWidget for my matDisplay class and promoted to matDisplay.
But when I use that same QWidget in my code to load image, It shows those same errors.
Error C2039 'SetRenderWindow': is not a member of 'matDisplay'
Error C2039 'GetInteractor': is not a member of 'matDisplay'(because it is promoted to only matDisplay and not to QVTKWidget)
I need only one widget where i can load dicom image (which are connected to render window and interactor in my code) and use that same widget to get coordinates of that dicom image.
Sorry I tried all ways, but don't understand how to achieve these both things using only one widget.
Kindly please help me. -
Inherit matWidget from QVTKWidget.