Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Get coordinates of dicom image by clicking anywhere on image in Qt
QtWS25 Last Chance

Get coordinates of dicom image by clicking anywhere on image in Qt

Scheduled Pinned Locked Moved Unsolved General and Desktop
23 Posts 5 Posters 2.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pvirk
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by SGaist
      #2

      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.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      P 1 Reply Last reply
      3
      • SGaistS SGaist

        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.

        P Offline
        P Offline
        pvirk
        wrote on last edited by
        #3

        @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.

        jsulmJ 1 Reply Last reply
        0
        • P pvirk

          @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.

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          P 1 Reply Last reply
          2
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @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.

            1 Reply Last reply
            1
            • jsulmJ jsulm

              @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

              P Offline
              P Offline
              pvirk
              wrote on last edited by
              #6

              @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.

              jsulmJ 1 Reply Last reply
              0
              • P pvirk

                @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.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by jsulm
                #7

                @pvirk Subclass QVTKWidget, override mousePressEvent() in your subclass and use that one instead of QVTKWidget
                https://vtk.org/doc/nightly/html/classQVTKWidget.html#aa92a6e9081f134c41ef985a44d7e90a6

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                0
                • P Offline
                  P Offline
                  pvirk
                  wrote on last edited by
                  #8

                  Sorry, but I don't know how to do it. I am new to Qt.
                  Could you please explain me in steps?
                  What exact changes I have to do, do I need any header file for it?

                  jsulmJ 1 Reply Last reply
                  0
                  • P pvirk

                    Sorry, but I don't know how to do it. I am new to Qt.
                    Could you please explain me in steps?
                    What exact changes I have to do, do I need any header file for it?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #9

                    @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.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    0
                    • P Offline
                      P Offline
                      pvirk
                      wrote on last edited by
                      #10

                      Screenshot (5).png

                      I did this, but do not understand what is wrong in it.
                      Do I need any header file?

                      KroMignonK jsulmJ 2 Replies Last reply
                      0
                      • P pvirk

                        Screenshot (5).png

                        I did this, but do not understand what is wrong in it.
                        Do I need any header file?

                        KroMignonK Offline
                        KroMignonK Offline
                        KroMignon
                        wrote on last edited by
                        #11

                        @pvirk said in Get coordinates of dicom image by clicking anywhere on image in Qt:

                        Do I need any header file?

                        At least you must include the definition of QVTKWidget ==> maybe #include <QVTKWidget> or #include <QVTKWidget.h> ?

                        It is an old maxim of mine that when you have excluded the impossible, whatever remains, however improbable, must be the truth. (Sherlock Holmes)

                        1 Reply Last reply
                        1
                        • P pvirk

                          Screenshot (5).png

                          I did this, but do not understand what is wrong in it.
                          Do I need any header file?

                          jsulmJ Offline
                          jsulmJ Offline
                          jsulm
                          Lifetime Qt Champion
                          wrote on last edited by
                          #12

                          @pvirk Sorry, it needs to be

                          class MyWidget : public QVTKWidget
                          {
                          protected:
                              void mousePressEvent(QMouseEvent * event) ;
                          }
                          

                          https://forum.qt.io/topic/113070/qt-code-of-conduct

                          1 Reply Last reply
                          0
                          • SGaistS Offline
                            SGaistS Offline
                            SGaist
                            Lifetime Qt Champion
                            wrote on last edited by
                            #13

                            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.

                            Interested in AI ? www.idiap.ch
                            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                            1 Reply Last reply
                            2
                            • P Offline
                              P Offline
                              pvirk
                              wrote on last edited by
                              #14

                              Okay. I will check C++ tutorials. Thank you so much everyone.

                              1 Reply Last reply
                              0
                              • P Offline
                                P Offline
                                pvirk
                                wrote on last edited by
                                #15

                                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.

                                1. Error C2039 'SetRenderWindow': is not a member of 'matDisplay'
                                2. 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.

                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #16

                                  What is matDisplay ?

                                  Interested in AI ? www.idiap.ch
                                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  1 Reply Last reply
                                  1
                                  • mrjjM Offline
                                    mrjjM Offline
                                    mrjj
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    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

                                    1 Reply Last reply
                                    0
                                    • P Offline
                                      P Offline
                                      pvirk
                                      wrote on last edited by
                                      #18

                                      Hello,
                                      'matDisplay' is class i created for mousepressevent.
                                      Screenshot (9).png Screenshot (8).png

                                      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?

                                      mrjjM 1 Reply Last reply
                                      0
                                      • P pvirk

                                        Hello,
                                        'matDisplay' is class i created for mousepressevent.
                                        Screenshot (9).png Screenshot (8).png

                                        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?

                                        mrjjM Offline
                                        mrjjM Offline
                                        mrjj
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        @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

                                        1 Reply Last reply
                                        1
                                        • P Offline
                                          P Offline
                                          pvirk
                                          wrote on last edited by
                                          #20

                                          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?
                                          Screenshot (12).png

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved