Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Matching 2 .tiff images pixel-by-pixel
Qt 6.12 LTS is out! See what's new in the release blog

Matching 2 .tiff images pixel-by-pixel

Scheduled Pinned Locked Moved Solved General and Desktop
55 Posts 5 Posters 43.7k 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
    #8

    I use this code: https://stackoverflow.com/questions/13840289/how-to-use-qrubberband-with-qrect-class-in-pyqt
    inside my widget, more specifically, this code:

    def mousePressEvent(self, event):
        self.origin = event.pos()
        self.rubberband.setGeometry(
            QtCore.QRect(self.origin, QtCore.QSize()))
        self.rubberband.show()
        QtGui.QWidget.mousePressEvent(self, event)
    
    def mouseMoveEvent(self, event):
        if self.rubberband.isVisible():
            self.rubberband.setGeometry(
                QtCore.QRect(self.origin, event.pos()).normalized())
        QtGui.QWidget.mouseMoveEvent(self, event)
    
    def mouseReleaseEvent(self, event):
        if self.rubberband.isVisible():
            self.rubberband.hide()
            selected = []
            rect = self.rubberband.geometry()
            for child in self.findChildren(QtGui.QPushButton):
                if rect.intersects(child.geometry()):
                    selected.append(child)
            print 'Selection Contains:\n ',
            if selected:
                print '  '.join(
                    'Button: %s\n' % child.text() for child in selected)
            else:
                print ' Nothing\n'
        QtGui.QWidget.mouseReleaseEvent(self, event)
    

    but I don't see any rectangle...

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

      Are you sure your methods are called ?

      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
        #10

        I use these method calls:

            self.mousePressEvent()
            self.mouseMoveEvent()
            self.mouseReleaseEvent()
        

        inside the main widget class..but what do I put inside the parenthesis? Because "event" does not seem to work...

        JonBJ 1 Reply Last reply
        0
        • J john_hobbyist

          I use these method calls:

              self.mousePressEvent()
              self.mouseMoveEvent()
              self.mouseReleaseEvent()
          

          inside the main widget class..but what do I put inside the parenthesis? Because "event" does not seem to work...

          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by JonB
          #11

          @john_hobbyist
          What do you mean by "I use these method calls"? These methods are supposed to be overrides. Qt infrastructure calls them when it detects the mouse event, with the appropriate event parameter.

          And anyway @SGaist was asking you put a debugging print() statement inside these override methods to make sure they are getting called.

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

            I am trying some ready examples in order to understand the rationale. I run the first code from here: https://stackoverflow.com/questions/34220275/how-to-select-a-region-with-qrubberband-on-a-qlabel-like-in-ksnapshot

            I have changed PyQt4 ---> PyQt5 and QtGui ----> QtWidgets. I also changed this line:

            pixmap = QPixmap.grabWindow(app.desktop().winId())
            

            with this:

            pixmap = QScreen.grabWindow(app.desktop().winId())
            

            but I get this error:

            File "QRubberBandonaQLabelKSnapshot.py", line 47, in initUI
                pixmap = QScreen.grabWindow(app.desktop().winId())
            TypeError: grabWindow(self, sip.voidptr, x: int = 0, y: int = 0, width: int = -1, height: int = -1): first argument of unbound method must have type 'QScreen'
            

            Any idea what to do here?

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

              You're using it as if it were a static method which it's not. You need an instance of QScreen.

              You can get one from your QApplication.

              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

                You're using it as if it were a static method which it's not. You need an instance of QScreen.

                You can get one from your QApplication.

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

                @SGaist Sorry I do not understand...how I get an instance from QApplication in QScreen?

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

                  It's the other way around.

                  In any case, you should rather get the screen from your widget.

                  Take a look at the screenshot example.

                  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 john_hobbyist
                    #16

                    @SGaist

                    I just try to see how to run the QRubberBand in PyQt5....

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

                      Did you check the example from the class documentation ?

                      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

                        I added them to the main class. I am trying to call the methods, like this:

                        self.mousePressEvent(event)
                        self.mouseMoveEvent(event)
                        

                        etc.

                        But what do I put inside/instead of "event"?

                        mrjjM 1 Reply Last reply
                        0
                        • J john_hobbyist

                          I added them to the main class. I am trying to call the methods, like this:

                          self.mousePressEvent(event)
                          self.mouseMoveEvent(event)
                          

                          etc.

                          But what do I put inside/instead of "event"?

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

                          @john_hobbyist

                          The code you showed higher up to drive the rubber band.
                          Or the docs @SGaist points to. they explain in detail what is needed.

                          def mousePressEvent(self, event):   ///// this set the start location of the band
                              self.origin = event.pos()
                              self.rubberband.setGeometry(
                                  QtCore.QRect(self.origin, QtCore.QSize()))
                              self.rubberband.show()
                              QtGui.QWidget.mousePressEvent(self, event)
                          
                          def mouseMoveEvent(self, event): // this makes the band follow the mouse to adjust the size
                              if self.rubberband.isVisible():
                                  self.rubberband.setGeometry(
                                      QtCore.QRect(self.origin, event.pos()).normalized())
                              QtGui.QWidget.mouseMoveEvent(self, event)
                          
                          def mouseReleaseEvent(self, event): // this is the end of the operation and you use the rectange defined by the band
                              if self.rubberband.isVisible():
                                  self.rubberband.hide()
                             rect = self.rubberband.geometry()
                          
                           ... then use rect for whatever you need
                          
                          1 Reply Last reply
                          2
                          • J Offline
                            J Offline
                            john_hobbyist
                            wrote on last edited by john_hobbyist
                            #20

                            @mrjj: Thanks for your help! I am searching all morning. Here https://doc.qt.io/qtforpython/PySide6/QtWidgets/QRubberBand.html#more I don't see something about what to put inside the "event". The only I can understand is to use this inside events: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QMouseEvent.html

                            mrjjM 1 Reply Last reply
                            0
                            • J john_hobbyist

                              @mrjj: Thanks for your help! I am searching all morning. Here https://doc.qt.io/qtforpython/PySide6/QtWidgets/QRubberBand.html#more I don't see something about what to put inside the "event". The only I can understand is to use this inside events: https://doc.qt.io/qtforpython-5/PySide2/QtGui/QMouseEvent.html

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

                              @john_hobbyist

                              Im not sure what you refer too ?

                              def mouseReleaseEvent(self, event): <<< this event ? the paramter ?

                              To use the rubberband, we use 3 functions as shown.

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

                                @mrjj
                                Yes, I try this:

                                self.mousePressEvent(event)
                                

                                and the code requires to put something instead of "event". This is the error:

                                File "code.py", line 310, in __init__
                                  self.mousePressEvent(event)
                                NameError: name 'event' is not defined
                                
                                1 Reply Last reply
                                0
                                • SGaistS Offline
                                  SGaistS Offline
                                  SGaist
                                  Lifetime Qt Champion
                                  wrote on last edited by
                                  #23

                                  Where are you calling these methods from ?

                                  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
                                    #24

                                    @SGaist : Inside this method:

                                    def __init__(self, parent=None):
                                       . . . 
                                       (code)
                                       . . . 
                                       self.mousePressEvent(event)
                                       self.mouseMoveEvent(event)
                                       self.mouseReleaseEvent(event)
                                    
                                    . . . 
                                    
                                    (other methods + code per method)
                                    
                                    . . . 
                                    
                                    def mousePressEvent(self, event):
                                       (code)
                                    
                                    def mouseMoveEvent(self, event):
                                       (code)
                                    
                                    def mouseReleaseEvent(self,event):
                                       (code)
                                       
                                    

                                    which the first method of the class. Any idea?

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

                                      That's not how it works. These methods are automatically called when appropriate.

                                      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

                                        That's not how it works. These methods are automatically called when appropriate.

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

                                        @SGaist : So I remove these lines?

                                        self.mousePressEvent(event)
                                        self.mouseMoveEvent(event)
                                        self.mouseReleaseEvent(event)
                                        

                                        What should I change?

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

                                          Implement the methods like shown in the QRubberBand class documentation.

                                          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

                                          • Login

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