PDA

View Full Version : QPainter bounds question



Micawber
23rd October 2007, 00:57
Lets suppose that in my custom repaint method, I create a painter and set a window size of, say ( -5000, -5000, 10000, 10000) and start to draw various points in to the window. Is there any way to query the painter for a bounding rectangle for only the points that I draw?

I would like to know because it would make scaling easier. IOW, I can scale such that all of my data points are contained in the viewport.

I get the feeling that I am going to have to keep track of it myself as I am painting and then scale it, but I wonder if the painter has such a capability.

Mic.

wysota
23rd October 2007, 08:16
I'm not exactly sure what you want, but you can query the widget's size by using QWidget::contentsRect() or the painter size (both logical and physical) by using QPainter::window() and QPainter::viewport().

Micawber
23rd October 2007, 12:21
What I need is a quick way to set the scale such that all of the data points are contained within the viewport. I was hoping that the painter would keep track of something like that so that it could be quickly retrieved.

wysota
23rd October 2007, 14:09
In my opinion all you need is to draw the data points using logical coordinates and set the range of those coordinates as the painter's window using QPainter::setWindow().