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
Forum Updated to NodeBB v4.3 + New Features

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.8k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    SGaist
    Lifetime Qt Champion
    wrote on 15 Jan 2020, 13:14 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 16 Jan 2020, 14:10
    3
    • S SGaist
      15 Jan 2020, 13:14

      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 16 Jan 2020, 14:10 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.

      J 1 Reply Last reply 16 Jan 2020, 14:58
      0
      • P pvirk
        16 Jan 2020, 14:10

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

        J Offline
        J Offline
        jsulm
        Lifetime Qt Champion
        wrote on 16 Jan 2020, 14:58 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 17 Jan 2020, 10:14
        2
        • M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 16 Jan 2020, 18:36 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
          • J jsulm
            16 Jan 2020, 14:58

            @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 17 Jan 2020, 10:14 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.

            J 1 Reply Last reply 17 Jan 2020, 10:18
            0
            • P pvirk
              17 Jan 2020, 10:14

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

              J Offline
              J Offline
              jsulm
              Lifetime Qt Champion
              wrote on 17 Jan 2020, 10:18 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 17 Jan 2020, 10:33 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?

                J 1 Reply Last reply 17 Jan 2020, 10:35
                0
                • P pvirk
                  17 Jan 2020, 10:33

                  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?

                  J Offline
                  J Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on 17 Jan 2020, 10:35 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 17 Jan 2020, 10:53 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?

                    K J 2 Replies Last reply 17 Jan 2020, 10:58
                    0
                    • P pvirk
                      17 Jan 2020, 10:53

                      Screenshot (5).png

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

                      K Offline
                      K Offline
                      KroMignon
                      wrote on 17 Jan 2020, 10:58 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
                        17 Jan 2020, 10:53

                        Screenshot (5).png

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

                        J Offline
                        J Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on 17 Jan 2020, 10:58 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
                        • S Offline
                          S Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on 17 Jan 2020, 10:59 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 17 Jan 2020, 11:08 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 18 Jan 2020, 16:57 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
                              • S Offline
                                S Offline
                                SGaist
                                Lifetime Qt Champion
                                wrote on 18 Jan 2020, 20:41 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
                                • M Offline
                                  M Offline
                                  mrjj
                                  Lifetime Qt Champion
                                  wrote on 18 Jan 2020, 22:31 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 19 Jan 2020, 09:26 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?

                                    M 1 Reply Last reply 19 Jan 2020, 11:06
                                    0
                                    • P pvirk
                                      19 Jan 2020, 09:26

                                      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?

                                      M Offline
                                      M Offline
                                      mrjj
                                      Lifetime Qt Champion
                                      wrote on 19 Jan 2020, 11:06 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 19 Jan 2020, 14:19 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
                                        • M Offline
                                          M Offline
                                          mrjj
                                          Lifetime Qt Champion
                                          wrote on 19 Jan 2020, 19:00 last edited by
                                          #21

                                          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

                                          1 Reply Last reply
                                          1

                                          11/23

                                          17 Jan 2020, 10:58

                                          • Login

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