Because QGIS has more than one way to accomplish a goal, here's another answer.
First, create a new layer in the CRS of your point coordinates. (If the point coordinates are in latitude and longitude, the CRS is EPSG:4326.) It doesn't matter what its geometry type is. Add four fields to the attribute table: xmin, xmax, ymin and ymax. Choose decimal number as the field type. Add a new feature, enter the xmin, xmax, ymin and ymax values from your corner points. Your top-left point is (xmin,ymax). Your bottom-right corner point is (xmax,ymin).
Use the Geometry by Expression
tool (from the processing toolbox)
Choose Input Layer: any layer that has the same CRS as the point coordinates.
Choose Output geometry type: Polygon
Use this for the Geometry expression:
make_polygon( make_line( make_point( xmin,ymin), make_point( xmin,ymax), make_point( xmax,ymax), make_point( xmax,ymin), make_point( xmin,ymin)))
Obviously this method is more complicated than my other suggestion. It doesn't make sense to do it this way for only one rectangle. But if you have a lot of rectangles to create, this method will be more efficient than running create grid
multiple times. Simply add as many features to the layer as you want to create rectangles.
qgis-plugins
- are you writing a plugin?