0

I understand that the co-ordinate system of a widget is local to the widget. 0,0 top left.

I want to draw a frame in the widget, but using the QRect returned by rect() will result in the right and bottom not framed.

There is a method called 'frameGeometry()' however this returns a QRect that is not in the same co-ordinate system as the widget, but in the parents co-orindate system.

Is there a way to get the framing rectangle for the widget in the local co-ordinate system.

I know I can translate the frameGeometry() or simply create a new rectangle:

    QRect(0, 0, width()-1, height()-1);

Is this the proper thing to do?

SPlatten
  • 5,334
  • 11
  • 57
  • 128

1 Answers1

0

The widget most likely has a padding for its canvas which you'll need to subtract from the widget's QRect (which describes the overall space the widget consumes, including padding on all sides) to obtain a rectangle that fits within your widget. Not sure about the specific syntax though.

starturtle
  • 699
  • 8
  • 25
  • Thank you, investigating now, there are methods called contentsRect() which returns the same rectangle as rect() and contentsMargins(), the margins returned are all 0. – SPlatten Jun 07 '16 at 10:20
  • When you read the QRect for your widget, it must have a BottomRight point. Are its coordinates smaller than the widget's Height and Width or just the same? Also, I'm now remembering what the issue with my VCL widgets was... They had a ContentPane that had a smaller bounding rectangle than the widget itself. Do your widgets have something like that, i.e., are they panel-ish? Don't know what kind of QWidget you're referring to, so can't look it up myself. Mine was the VCL element corresponding to QPushButton. – starturtle Jun 07 '16 at 11:45
  • You are quite right the bottom right is 1 pixel inset. – SPlatten Jun 07 '16 at 12:09