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

Ioannis Nousias s0238762 at sms.ed.ac.uk
Sat Apr 4 15:52:15 CEST 2009


Hello Qt users/developers,

I'm new to Qt and currently exploring its features, before I can use it 
for a project of mine.

Before I ask my question, let me give you a sort description of my test 
case. I've made my own version of the 'scribble' example provided by the 
Qt demos package. In this version, each shape is stored as a 
QPainterPath (along with an associated QPen, wrapped in what I call a 
pathContext). A new path is created on mousePressEvent. The paintEvent 
goes through the list of paths and strokePath() them on the widget's 
drawing area, using their companion QPen.

In the mouseMoveEvent (I've set mouse tracking on), I iterate through 
the list of paths and using QPainterPath::contains(), I detect if the 
current mouse pointer is over a given path, in which case I change the 
QPen colour for that path to 'Qt::red', otherwise it's set to 
'Qt::blue'. The end effect is, when the mouse pointer hovers over a 
path, the path gets highlighted red.

Now imagine a U shaped path. The problem I have is that 'contains()' 
returns a positive response even when the mouse pointer is over the 
inner cavity of the U shape, as if the path is closed and filled. The 
required behaviour is for 'contains()' to return a positive response 
only if the mouse is over the stroke line of the path-shape.

Is there a way to do this?


thank you,
Ioannis




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




More information about the Qt-interest-old mailing list