from PyQt5.QtCore import QPointF # Create a point object pt = QPointF(3.5, 4.0) # Print the coordinates of the point print(pt.x()) # Output: 3.5 print(pt.y()) # Output: 4.0
from PyQt5.QtCore import QPointF # Create a list of points points = [QPointF(0, 0), QPointF(5, 10), QPointF(1, 3), QPointF(-4, 6)] # Sort the points in ascending order of their x-coordinates sorted_points = sorted(points, key=lambda point: point.x()) # Print the sorted points for point in sorted_points: print(point.x(), point.y()) # Output: # -4.0 6.0 # 0.0 0.0 # 1.0 3.0 # 5.0 10.0This example shows how to use the QPointF class in a sorting function to sort a list of points based on their x-coordinates. The lambda function passed to the sorted() method specifies the sorting criteria to be used.