I've written a custom widget in Qt that subclasses and does custom painting, however it's a non-rectangular object (has a polygon top area), and it's working fine, however when adding layouts they 'break' into the top area as it's getting the wrong boundary area. Is there anyway I can specify within the custom widget what the boundary area is for child widgets?
Asked
Active
Viewed 259 times
1 Answers
1
One way is to use QLayout::setContentsMargins
on the widget's layout.
If you want a boundary that's not rectangular, you can use a grid layout filled with fixed-size rectangular fillers. The fillers can be derived from the polygon using scanline conversion -- just merge a number of scanlines into a taller bounding rectangle and use it for fillers.

Community
- 1
- 1

Kuba hasn't forgotten Monica
- 95,931
- 16
- 151
- 313
-
I'm doing something similar at the moment, but it'd be nice if I didn't have to. – Nicholas Smith Jun 16 '12 at 14:53
-
1Well, you want to set the boundary, and voila, here is exactly how you'd set such a rectangular boundary. If you want a boundary that's not rectangular, you can use a grid layout filled with fixed-size rectangular fillers. The fillers can be derived from the polygon using [scanline conversion](http://stackoverflow.com/a/11043448/1329652) -- just merge a number of scanlines into a taller bounding rectangle and use it for filler. – Kuba hasn't forgotten Monica Jun 16 '12 at 16:37
-
Ah hah, I misread the documentation and this is actually what I needed! – Nicholas Smith Jun 17 '12 at 15:30