Skip to content

Commit

Permalink
Merge pull request #5712 from ericmehl/offsetClickCoordinate
Browse files Browse the repository at this point in the history
Offset Widget click line by 0.5 pixel
  • Loading branch information
ericmehl authored Mar 5, 2024
2 parents 4932b73 + 6b3eca6 commit 20d8c16
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ API
- ScenePath : Added automatic conversion of a list of Python strings to a ScenePath [^1].
- RenderPassEditor : Added `registerPathGroupingFunction()` and `pathGroupingFunction()` methods [^1].
- ExtensionAlgo : Added `exportNode()` and `exportNodeUI()` functions.
- Widget : Added a 0.5 pixel offset to `ButtonEvent.line` objects passed to mouse event signals such as `buttonPressSignal()` and `dragMoveSignal()`

Breaking Changes
----------------
Expand Down
4 changes: 2 additions & 2 deletions python/GafferUI/Widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1656,8 +1656,8 @@ def __widgetSpaceLine( self, qEvent, targetWidget ) :
cursorPos -= targetWidget.bound().min()

return IECore.LineSegment3f(
imath.V3f( cursorPos.x, cursorPos.y, 1 ),
imath.V3f( cursorPos.x, cursorPos.y, 0 )
imath.V3f( cursorPos.x + 0.5, cursorPos.y + 0.5, 1 ),
imath.V3f( cursorPos.x + 0.5, cursorPos.y + 0.5, 0 )
)

# this single instance is used by all widgets
Expand Down
17 changes: 17 additions & 0 deletions python/GafferUITest/WidgetTest.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,5 +604,22 @@ def _displayTransformChanged( self ) :
window1.addChildWindow( window3 )
self.assertEqual( window3.getChild().displayTransformChanges, [ displayTransform2 ] )

def testButtonPressSignalLine( self ) :

w = TestWidget()

def f( w, event ) :

self.assertEqual( event.line.p0.x - int( event.line.p0.x ), 0.5 )
self.assertEqual( event.line.p0.y - int( event.line.p0.y ), 0.5 )
self.assertEqual( event.line.p1.x - int( event.line.p1.x ), 0.5 )
self.assertEqual( event.line.p1.y - int( event.line.p1.y ), 0.5 )

w.buttonPressSignal().connect( f, scoped = False )

event = QtGui.QMouseEvent( QtCore.QEvent.MouseButtonPress, QtCore.QPoint( 10, 10 ), QtCore.Qt.LeftButton, QtCore.Qt.LeftButton, QtCore.Qt.NoModifier )

QtWidgets.QApplication.instance().sendEvent( w._qtWidget(), event )

if __name__ == "__main__":
unittest.main()

0 comments on commit 20d8c16

Please sign in to comment.