[Qt-interest] QPainterPath::contains() alternative behaviour

Ioannis Nousias s0238762 at sms.ed.ac.uk
Sun Apr 5 02:45:25 CEST 2009


Jonathan Kew wrote:
> On 4 Apr 2009, at 23:58, Ioannis Nousias wrote:
>
>> Jonathan Kew wrote:
>>> On 4 Apr 2009, at 17:47, Ioannis Nousias wrote:
>>>
>>>
>>>> yes, I've tried that, but contains() didn't trigger at all. Just to 
>>>> make sure I'm not doing something wrong, here is what I did:
>>>>
>>>> QPainterPathStroker stroker;
>>>> QPainterPath stroke = stroker.createStroke(path);
>>>>
>>>> bool contains = stroke.contains
>>>> (
>>>> QRectF(event->pos(),event->pos())
>>>> .adjusted(-0.5,-0.5,0.5,0.5)
>>>> );
>>>>
>>>>
>>>
>>> Perhaps you need to set the width of the QPainterPathStroker? The 
>>> documentation doesn't seem to mention a default....perhaps it's too 
>>> narrow to hit.
>>>
>>> JK
>>>
>>>
>>
>> My understanding is that paths have no width. It's the Pen that you 
>> use that defines the width and other such properties. Am I right?
>
> Yes, I believe so.
>
> But when you use QPainterPathStroker, it has no idea what pen you 
> might be intending to use (or have already used) for drawing the path; 
> all you're giving it in createStroke() is the actual path, no pen 
> information.
>
> However, it does have a setWidth() method of its own (and similarly 
> for other characteristics: dashes, mitre limit, etc). That's what I 
> think you may need to set, to match the characteristics of the pen 
> you're planning to use. Otherwise, how can it create a new path that 
> corresponds to the outline of what that pen would draw?
>
> So I'm suggesting you try
>
> stroker.setWidth(<the width of your pen>);
>
> before calling stroker.createStroke(path).
>
> JK
>
>
excellent :) that is the solution.

thanks Jonathan,
Ioannis



PS: I missed that QPainterPathStroker has a 'setWidth()' method. I was 
looking at QPainterPath.

-- 
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.




More information about the Qt-interest-old mailing list