[Qt-interest] which key(s) pressed for current widget?

James Yan jyan972 at gmail.com
Wed Dec 17 13:19:44 CET 2008


OK, the idea using keyPressEvent/keyReleaseEvent for my problem is just
works. some bugs occurs when before i write previous mail.

On Wed, Dec 17, 2008 at 8:03 PM, James Yan <jyan972 at gmail.com> wrote:

> hey all,
>
>  i create a widget where i can draw and move points on it, and allow user
> to move points with two methods, so i want to separate two methods with
> user's key press: if CTRL is pressed or not while mouse moved.
>
> so i think it can be impletmented with keyPressEvent / keyReleaseEvent in
> this way:
>
> mywidget::keyPressEvent( QKeyEvent * event )
> {
>    key = event->key(); //save which key pressed
> }
>
>
> mywidget::keyReleaseEvent ( QKeyEvent * event )
> {
>    key = -1; // no key pressed from now
> }
>
> mywidget::movePoint()
> {
>     if(key == CTRL)
>    {
>         //move points with method #1
>    }
>    else
>    {
>         //move points with method #2
>    }
> }
>
> but the result of above idea and code do not works, i already
> setFocusPolicy so widget can revice key.
> any wrong with it? my problem can be solved with keyPressEvent /
> keyReleaseEvent?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20081217/bac01549/attachment.html 


More information about the Qt-interest-old mailing list