[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-devel
Subject:    Re: question about QMouseEvents
From:       Dominique Devriese <dominique.devriese () student ! kuleuven ! ac ! be>
Date:       2003-08-29 22:48:53
[Download RAW message or body]

Jason Harris writes:

> Hello, I need to check if the user has pressed the left mouse button
> while holding down the CTRL key.

> This doesn't work:
>   if ( e->state() & ( ControlButton & LeftButton ) )

Logical, what you mean is:
if( e->state() & ( ControlButton | LeftButton ) )

because ControlButton is something like this ( in binary ):
00000010000 and LeftButton would be 00000001000, and you want
00000011000, not 000000000000.  ( I know the zero counts are wrong ;),
it's just an example ;) )

However, this won't work either, see below..

> Nor this:
>   if ( (e->state() & ControlButton) && (e->state() & LeftButton ) )

man qmouseevent -> under state():
       Returns the button state (a combination of mouse buttons and
       keyboard modifiers), i.e. what buttons and keys were
       being pressed immediately before the event was generated.

       Note that this means that for QEvent::MouseButtonPress and
       QEvent::MouseButtonDblClick, the flag for the button()
       itself will not be set in the state, whereas for
       QEvent::MouseButtonRelease it will.

The note above says it all, I would think...

> But this does:
>   if ( (e->state() & ControlButton) && (e->button() == LeftButton )
>   )

see above.

cheers
domi
 
>> Visit http://mail.kde.org/mailman/listinfo/kde-devel#unsub to unsubscribe <<
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic