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

Get upper left and down right coordinates from zoomed image

Scheduled Pinned Locked Moved Unsolved Qt for Python
25 Posts 3 Posters 4.1k 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.
  • 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
                                  • SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #21

                                    Why are you needing to add tkinter to your Qt application ?

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

                                    J 1 Reply Last reply
                                    1
                                    • SGaistS SGaist

                                      Why are you needing to add tkinter to your Qt application ?

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

                                      @SGaist I tried qrubberband in the past (https://stackoverflow.com/questions/13840289/how-to-use-qrubberband-with-qrect-class-in-pyqt and https://stackoverflow.com/questions/34220275/how-to-select-a-region-with-qrubberband-on-a-qlabel-like-in-ksnapshot) but it didn't work! Also I need to get coordinates of the corners of the selected area and tkinter is very easy on this...

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

                                          Ok, never mind, I solved it 80%. Another point, in the previously mentioned code (https://github.com/Axel-Erfurt/OrthoViewLite/blob/main/OrthoViewLite.py) in which part does the "store image" button be related? I have put "prints" in the entire code, nowhere I see an action on prints, when I zoom in and store the current image...

                                          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