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. Unable to make a simple selection rectangle by taking rect between two points.... all day!
Forum Update on Monday, May 27th 2025

Unable to make a simple selection rectangle by taking rect between two points.... all day!

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 592 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.
  • enjoysmathE Offline
    enjoysmathE Offline
    enjoysmath
    wrote on last edited by
    #1
    class SelectionRect(QGraphicsRectItem):
        def __init__(self, scene, parent=None):
            QGraphicsRectItem.__init__(self, parent)
            self.setBrush(QBrush(Qt.NoBrush))
            self.viewScaleX = 1.0
            self.viewScaleY = 1.0
            scene.addItem(self)
            self.setPen(self.createPen())
            self.setVisible(False)
            self.setZValue(sys.float_info.max)
            
        def setCorners(self, p1, p0=None):
            if p0 == None:
                p0 = self.pos()
            rect = rectThroughPoints(p0, p1)
            self.setPos(rect.topLeft())
            self.setRect(QRectF(0, 0, rect.width(), rect.height()))
    
    I use setCorners to position the selection rect every mouse move event in a qgraphicsscene.
    
    the behavior is it's working for everything but moving the edges of the selection rectangle up or left
    

    https://github.com/enjoysmath
    https://math.stackexchange.com/users/26327/exercisingmathematician

    enjoysmathE 1 Reply Last reply
    0
    • enjoysmathE enjoysmath
      class SelectionRect(QGraphicsRectItem):
          def __init__(self, scene, parent=None):
              QGraphicsRectItem.__init__(self, parent)
              self.setBrush(QBrush(Qt.NoBrush))
              self.viewScaleX = 1.0
              self.viewScaleY = 1.0
              scene.addItem(self)
              self.setPen(self.createPen())
              self.setVisible(False)
              self.setZValue(sys.float_info.max)
              
          def setCorners(self, p1, p0=None):
              if p0 == None:
                  p0 = self.pos()
              rect = rectThroughPoints(p0, p1)
              self.setPos(rect.topLeft())
              self.setRect(QRectF(0, 0, rect.width(), rect.height()))
      
      I use setCorners to position the selection rect every mouse move event in a qgraphicsscene.
      
      the behavior is it's working for everything but moving the edges of the selection rectangle up or left
      
      enjoysmathE Offline
      enjoysmathE Offline
      enjoysmath
      wrote on last edited by
      #2

      @enjoysmath Found it, up or left self.pos() is no longer the appropriate corner

      https://github.com/enjoysmath
      https://math.stackexchange.com/users/26327/exercisingmathematician

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

        Hi,

        Glad you found out and thanks for sharing !

        Since you have it working now, please mark the thread as solved using the "Topic Tools" button so that other forum users may know a solution has been found :)

        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
        0

        • Login

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