I'm having a play with Qt and can draw what I want, perform transforms, more the origin with a translation but would like to know how big the area I have to paint on is and is it possible to control this. I've read the entries for things like Viewport and clipping which seem as if they might have something to do with this but I'm not familure with termanlogy so I'm not understanding exactly what they are reffering to.

Could some please provide me with or point me in the direction of a explaination of what these terms are and if they are nothing to do with the area I have to paint on can you point me in the direction of how to work this out.

3 Years
Discussion Span
Last Post by TheBrick

The viewport is the rectangular area on which pixels can be drawn. This is usually defined as a corner offset (position of the lower-left corner, i.e., the origin) and a width and height (watch out: some GUI systems or libraries will use the upper-left corner as the origin instead, meaning the y-axis is pointing downwards). GUI systems are all about embedding things into others, and thus, viewports are always relative to a specific context which has limits of its own. In Windows, these contexts are called Device Contexts (or DC) and things like a window can provide a DC (or multiple partitioned DCs) on which other things can be drawn (buttons, menus, etc.). When you have something like a QPainter, it resides on a DC given from its parent window / widget and that bounds its area on which things can be drawn, it then uses part of it (maybe) to draw some borders or whatever and exposes whatever is left as a canvas (or a surface on which to draw things). Then, there are usually good reasons to want to create different rectangles to draw on, at least temporarily, and these are viewports. Normally, you set the viewport to one place (and size), draw some stuff, then move the viewport elsewhere (with new size) and draw some more stuff. So, the viewport is usually this area of the device context (or rendering context) in which you are currently drawing things (and clipping things).

Clipping is the act of removing anything that falls outside the viewport (or an otherwise-specified clipping area). For example, if you draw a line that ends outside the viewport, clipping will cause the part of the line outside the viewport to be clipped (i.e., not drawn). Obviously, clipping has to be done, at least at the final stage when pixels are being drawn, but it is often done in multiple stages to avoid unnecessary work. For example, quickly check if an object (line, circle, whatever else) falls entirely outside the viewport, then you can just stop there (i.e., no need to generate the pixels). This is an important part of any 3D rendering pipeline and occurs at multiple levels: the GPU will clip polygons outside the viewport and then pixels outside the viewport; and before that, the game engine / renderer will clip objects outside the camera's frustrum (first with space partitioning and then with simple rejection tests).

As for QPainter specifically, I recommend this page. For getting the actual width and height of the area to paint on, you need to get to the QPaintDevice (e.g., analogous to the Device Context I was describing above), which is the ultimate thing that defines the area you can draw on. By default, the QPainter sets the viewport to be equal to the device's entire area.


That make sense thanks. I like the idea of drawing in diffrent sections e.t.c. I'll take a read of your links. Thanks.


Found the dimension of the QPaintDevice now. Simple. Its leaning this hole new world of terminology.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.