Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Get upper left and down right coordinates from zoomed image
Forum Updated to NodeBB v4.3 + New Features

Get upper left and down right coordinates from zoomed image

Scheduled Pinned Locked Moved Unsolved Qt for Python
25 Posts 3 Posters 3.9k 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.
  • J Offline
    J Offline
    john_hobbyist
    wrote on last edited by john_hobbyist
    #1

    Hello, I use this code: https://github.com/Axel-Erfurt/OrthoViewLite/blob/main/OrthoViewLite.py When I choose an image and then I zoom in, how can I get the coordinates of each corner of the zoomed image, printed in terminal (and stored in variables)?

    1 Reply Last reply
    0
    • J Offline
      J Offline
      john_hobbyist
      wrote on last edited by
      #2

      Is it so difficult what I am asking?

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

        Hi,

        Please show some patience and allow at least 24 hours before bumping your own thread. This is a voluntary driven forum and people may not live in the same time zone as you.

        As for your question, you might want to consider providing more information. What you do here is to tell people to go read an entire Python script, understand what it does, find where the zoom happens, understand how the zoom is applied, and then possibly answer your question. Do you really think that this is something motivating ?

        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
        • J Offline
          J Offline
          john_hobbyist
          wrote on last edited by
          #4

          Ok, I managed to write some code, that seems to work. However, I am thinking of putting a button(icon) on the right side of the right series of buttons that exist in the APP. The idea is to put an icon with a very small image that would change to another image when the button is pressed on/off ( like a switch) . I am trying to combine this:

              select_btn = QAction("Select area on image")
          

          with this:

          https://stackoverflow.com/questions/44453268/creating-custom-pyqt5-image-button

          This is very general: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QIcon.html

          Any ideas??

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

            From memory, make your button checkable and use the On and Off state of QIcon to show your different images.

            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
            • J Offline
              J Offline
              john_hobbyist
              wrote on last edited by
              #6

              Ok, I searching it. The code that I want to execute when I "switch on" the button icon has methods defined inside. How can I handle this situation? I mean: I attached the "method2" obviously when the button is pressed (switch on):

              button2 = QAction("area selection", self, triggered=self.method2)
              

              but: can inside method2 define other methods?

              def method2():
                  def do_this():
                  . . . 
                  def do_that():
                  . . .
              
              jsulmJ 1 Reply Last reply
              0
              • J john_hobbyist

                Ok, I searching it. The code that I want to execute when I "switch on" the button icon has methods defined inside. How can I handle this situation? I mean: I attached the "method2" obviously when the button is pressed (switch on):

                button2 = QAction("area selection", self, triggered=self.method2)
                

                but: can inside method2 define other methods?

                def method2():
                    def do_this():
                    . . . 
                    def do_that():
                    . . .
                
                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                can inside method2 define other methods?

                Why do you want to define functions inside a method?

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

                J 1 Reply Last reply
                1
                • jsulmJ jsulm

                  @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                  can inside method2 define other methods?

                  Why do you want to define functions inside a method?

                  J Offline
                  J Offline
                  john_hobbyist
                  wrote on last edited by
                  #8

                  @jsulm I wrote the code for area selection alone to see if it works, outside the main program, in a different file. But now I need to include it to the main PyQt5 code in order to make it run when I switch on the button. Do you have a better suggestion?

                  jsulmJ 1 Reply Last reply
                  0
                  • J john_hobbyist

                    @jsulm I wrote the code for area selection alone to see if it works, outside the main program, in a different file. But now I need to include it to the main PyQt5 code in order to make it run when I switch on the button. Do you have a better suggestion?

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

                    @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                    I wrote the code for area selection alone to see if it works, outside the main program, in a different file. But now I need to include it to the main PyQt5 code in order to make it run when I switch on the button. Do you have a better suggestion?

                    This does not explain at all why you think you need to define functions inside a method. Why don't you define those functions as normal methods in the same class?

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

                    J 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                      I wrote the code for area selection alone to see if it works, outside the main program, in a different file. But now I need to include it to the main PyQt5 code in order to make it run when I switch on the button. Do you have a better suggestion?

                      This does not explain at all why you think you need to define functions inside a method. Why don't you define those functions as normal methods in the same class?

                      J Offline
                      J Offline
                      john_hobbyist
                      wrote on last edited by
                      #10

                      @jsulm I find it more easy to program it with methods.
                      So the idea is that I call a "method_1" when the button is pressed. This "method_1" calls an instance of the "class_1". "Class_1" includes the code for area selection. The problem is that when I run the pyqt5 code , only the "class_1" is executed!!!

                      jsulmJ 1 Reply Last reply
                      0
                      • J john_hobbyist

                        @jsulm I find it more easy to program it with methods.
                        So the idea is that I call a "method_1" when the button is pressed. This "method_1" calls an instance of the "class_1". "Class_1" includes the code for area selection. The problem is that when I run the pyqt5 code , only the "class_1" is executed!!!

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

                        @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                        This "method_1" calls an instance of the "class_1"

                        How is this related to functions inside a method?!
                        If you want to call a method on a class then you need an instance of that class.

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

                        J 1 Reply Last reply
                        1
                        • jsulmJ jsulm

                          @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                          This "method_1" calls an instance of the "class_1"

                          How is this related to functions inside a method?!
                          If you want to call a method on a class then you need an instance of that class.

                          J Offline
                          J Offline
                          john_hobbyist
                          wrote on last edited by john_hobbyist
                          #12
                          This post is deleted!
                          1 Reply Last reply
                          0
                          • J Offline
                            J Offline
                            john_hobbyist
                            wrote on last edited by john_hobbyist
                            #13
                            This post is deleted!
                            1 Reply Last reply
                            0
                            • J Offline
                              J Offline
                              john_hobbyist
                              wrote on last edited by
                              #14

                              After a lot of google searching and experiments I resulted in this concept:

                              class area:
                                  def __call__(self):
                                      x = 0, y = 0  # step 1
                                  
                                      def read_cursor(action):
                                          x = read_x
                                          y = read_y
                                          . . .
                                      def do_something(action):
                                          . . .
                              

                              The problem that x,y are not being updated when I move mouse. How do I pass the new updated mouse coordinates from read_cursor() function to ones in # step 1??

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

                                You should provide a minimal runnable script that shows what you want to do with that piece of code.

                                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
                                • J Offline
                                  J Offline
                                  john_hobbyist
                                  wrote on last edited by
                                  #16

                                  My code above is very simple. I need only to update x, y values (#step1), if someone can help me...

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

                                    Your code is incomplete and without context.
                                    It does not allow to understand the logic you want to implement.

                                    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
                                    • J Offline
                                      J Offline
                                      john_hobbyist
                                      wrote on last edited by john_hobbyist
                                      #18

                                      The idea is that I have a function embedded to another function. Generally speaking, how can I pass values from the inner function to the outer function?

                                      jsulmJ 1 Reply Last reply
                                      0
                                      • J john_hobbyist

                                        The idea is that I have a function embedded to another function. Generally speaking, how can I pass values from the inner function to the outer function?

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

                                        @john_hobbyist said in Get upper left and down right coordinates from zoomed image:

                                        how can I pass values from the inner function to the outer function?

                                        By returning them

                                        def __call__(self):
                                            def read_cursor(action):
                                                x = read_x
                                                y = read_y
                                                return (x, y)
                                        
                                            x, y = read_cursor(action)
                                        

                                        I still don't understand why you need nested functions...

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

                                        1 Reply Last reply
                                        2
                                        • J Offline
                                          J Offline
                                          john_hobbyist
                                          wrote on last edited by john_hobbyist
                                          #20

                                          @jsulm I need to get the returned values when I call the function like this:

                                          frame.bind("<Button-1>", callback)
                                          

                                          So, in the position of

                                          def read_cursor
                                          

                                          put the

                                          def callback
                                          

                                          function

                                          Please look here: https://web.archive.org/web/20201111211515id_/https://effbot.org/tkinterbook/tkinter-events-and-bindings.htm

                                          How can I achieve that? I use tkinter auxiliary to PyQt5

                                          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