Results 1 to 5 of 5

Thread: Keyboard Handling

  1. #1
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Keyboard Handling

    I am working on my video player some more and want to add in keyboard handling. I want to be able to use the space bar or right arrow key to move ahead x-number of frames that are chosen by the user using a QSpinBox. I have this QSpinBox as well as a number of buttons on my interface for the mouse to use. The problem is with using these certain keys, the focus just moves around from object to object. So I had my QAxWidget call grabKeyboard( ) so I could handle for the space bar and arrow pressing. But I also want to be able to type in a number into the QSpinBox instead of using the mouse to scroll to a value. I thought about giving the QSpinBox control of the keyboard in an if-statement in my KeyPress event handler and then after capturing the input set the focus outside the QSpinBox and give the keyboard back to the QAxWidget so it could handle it like before. Unfortunately, upon giving the control back to the QSpinBox, I never enter the KeyPress event handler so I cannot give the control back to the QAxWidget. Is there anyway I can do what I am trying to do. Does this make sense to anyone? Thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Re: Keyboard Handling

    Well I think I got it working partways. Inside my player constructor I added
    Qt Code:
    1. mySpinBox->installEventFilter( this )
    To copy to clipboard, switch view to plain text mode 
    and this allows me to use the right, left, and space bar like I want to. But the problem I get now is after I load my video, the up and down buttons on the QSpinBox disappear. They are there before I load in the video, but when I load the video, they disappear. Any ideas what would cause these buttons on the QSpinBox to disappear? The textbox portion of the QSpinBox is still there however and I can click just to the right of the box and the buttons still work, they just do not appear on the video player. Thanks!

  3. #3
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Keyboard Handling

    Its very hard to say without code.
    But it could be that for some reason paint events are not getting to the spin box.

  4. #4
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Keyboard Handling

    what does your event filter look like? just checking if it calls the default event handler for events it doesn't want...
    Software Engineer



  5. #5
    Join Date
    Jan 2006
    Location
    Ohio
    Posts
    332
    Thanks
    37
    Thanked 8 Times in 4 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Red face Re: Keyboard Handling

    Here is my event handler. As you can see I am trying to handle a variety of things. I will include repaintWindow( ) after this code so you can see what repaintWindow is doing since it is so vital to my project. repaintWindow() is mostly DirectShow functionality with a QLabel being drawn over the video...a 5 pixel-by-5 pixel QLabel. Does it look like my eventHandler is working correctly? Thanks!

    Qt Code:
    1. /*
    2.  * Event handler for the any widget using the installEventFilter function
    3.  */
    4. bool VideoViewerWindow::eventFilter( QObject *obj, QEvent *event )
    5. {
    6. if( obj == mpVideoPlayer )
    7. {
    8. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
    9. // Mouse Button Release handlers
    10. if( event->type() == QEvent::MouseButtonPress )
    11. {
    12. AzElPoint point;
    13. int azElSize = azElPoints.size( );
    14. point.frameNumber = getCurrentFrame( );
    15. point.xPos = mouseEvent->x( );
    16. point.yPos = mouseEvent->y( );
    17.  
    18. if( mouseEvent->button() == Qt::LeftButton )
    19. {
    20. // If left button, place mark on overlay to indicate position
    21. // and store position in array at the current frame index
    22. for( int i = 0 ; i < azElSize ; i++ )
    23. {
    24. if( azElPoints[i].frameNumber == point.frameNumber )
    25. {
    26. azElPoints.removeAt( i );
    27. erasePoint = true;
    28. break;
    29. }
    30. }
    31. azElPoints.push_back( point );
    32. return true;
    33. }
    34. }
    35. if( event->type() == QEvent::MouseButtonRelease )
    36. {
    37. if( mouseEvent->button() == Qt::RightButton )
    38. {
    39. // If right button, remove any point located in current frame
    40. AzElPoint point;
    41. point.frameNumber = getCurrentFrame( );
    42. point.xPos = mouseEvent->x( );
    43. point.yPos = mouseEvent->y( );
    44. for( int i = 0 ; i < azElPoints.size( ) ; i++ )
    45. {
    46. if( azElPoints[i].frameNumber == getCurrentFrame( ) &&
    47. ( azElPoints[i].xPos >= point.xPos - 2 && azElPoints[i].xPos <= point.xPos + 2 ) &&
    48. ( azElPoints[i].yPos >= point.yPos - 2 && azElPoints[i].yPos <= point.yPos + 2 ) )
    49. {
    50. azElPoints.removeAt( i );
    51. break;
    52. }
    53. }
    54. update( );
    55. return true;
    56. }
    57. }
    58. }
    59. if( event->type( ) == QEvent::Move )
    60. {
    61. if( pMediaSeeking != NULL )
    62. {
    63. repaintWindow( );
    64. return true;
    65. }
    66. }
    67. if( event->type( ) == QEvent::Paint )
    68. {
    69. if( pMediaSeeking != NULL )
    70. {
    71. repaintWindow( );
    72. return true;
    73. }
    74. }
    75. if( event->type( ) == QEvent::KeyPress )
    76. {
    77. if( pMediaSeeking!= NULL )
    78. {
    79. QKeyEvent *pressedKey = (QKeyEvent*) event;
    80. int key = pressedKey->key( );
    81. switch( key )
    82. {
    83. case Qt::Key_Space:
    84. pressedKey->accept( );
    85. skipAheadPressed( );
    86. return true;
    87. break;
    88. case Qt::Key_Right:
    89. pressedKey->accept( );
    90. skipAheadPressed( );
    91. return true;
    92. break;
    93. case Qt::Key_Left:
    94. pressedKey->accept( );
    95. skipBackPressed( );
    96. return true;
    97. break;
    98. case Qt::Key_P:
    99. pressedKey->accept( );
    100. pausePressed( );
    101. return true;
    102. break;
    103. case Qt::Key_S:
    104. pressedKey->accept( );
    105. stopPressed( );
    106. return true;
    107. break;
    108. case Qt::Key_Home:
    109. pressedKey->accept( );
    110. jumpToStartPressed( );
    111. return true;
    112. break;
    113. case Qt::Key_End:
    114. pressedKey->accept( );
    115. jumpToEndPressed( );
    116. return true;
    117. break;
    118. default:
    119. pressedKey->ignore( );
    120. }
    121. }
    122. }
    123. return QObject::eventFilter( obj, event );
    124. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /*
    2.  *
    3.  * repaintWindow( )
    4.  *
    5.  * This function repaints the video in its video frame so that the video will be
    6.  * upon loading and flipping back and forth between open windows.
    7.  *
    8.  */
    9. void VideoViewerWindow::repaintWindow( )
    10. {
    11. long lWidth, lHeight;
    12. HRESULT hr = pWindowlessControl->GetNativeVideoSize( &lWidth, &lHeight, NULL, NULL );
    13. RECT rcSrc, rcDest;
    14. // Set the source rectangle.
    15. SetRect( &rcSrc, 0, 0, lWidth, lHeight );
    16.  
    17. // Get the window client area.
    18. GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcDest );
    19. // Set the destination rectangle.
    20. SetRect(&rcDest, 1, 1, 558, 349);
    21.  
    22. // Set the video position.
    23. hr = pWindowlessControl->SetVideoPosition( &rcSrc, &rcDest );
    24.  
    25. PAINTSTRUCT ps;
    26. HDC hdc;
    27. RECT rcClient;
    28. GetClientRect( (HWND) mpVideoPlayer->winId( ), &rcClient );
    29. hdc = BeginPaint( (HWND) mpVideoPlayer->winId( ), &ps );
    30. if( pWindowlessControl != NULL )
    31. {
    32. // Find the region where the application can paint by subtracting
    33. // the video destination rectangle from the client area.
    34. // (Assume that g_rcDest was calculated previously.)
    35. HRGN rgnClient = CreateRectRgnIndirect( &rcClient );
    36. HRGN rgnVideo = CreateRectRgnIndirect( &rcDest );
    37. CombineRgn( rgnClient, rgnClient, rgnVideo, RGN_DIFF );
    38.  
    39. // Paint on window.
    40. HBRUSH hbr = GetSysColorBrush( COLOR_BTNFACE );
    41. FillRgn( hdc, rgnClient, hbr );
    42.  
    43. // Clean up.
    44. DeleteObject( hbr );
    45. DeleteObject( rgnClient );
    46. DeleteObject( rgnVideo );
    47.  
    48. int azElSize = azElPoints.size( );
    49. int currentFrame = getCurrentFrame( );
    50.  
    51. // Request the VMR to paint the video and draw the point chosen by the user.
    52. int i;
    53. for( i = 0 ; i < azElSize ; i++ )
    54. {
    55. if( azElPoints[i].frameNumber == currentFrame )
    56. {
    57. mpOverlayLabel->move( azElPoints[i].xPos - 2, azElPoints[i].yPos - 2 );
    58. mpOverlayLabel->show( );
    59. break;
    60. }
    61. }
    62. if( i == azElPoints.size( ) )
    63. {
    64. mpOverlayLabel->hide( );
    65. }
    66. HRESULT hr = pWindowlessControl->RepaintVideo( (HWND) mpVideoPlayer->winId( ), hdc );
    67. }
    68. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Fast Keyboard, help !
    By Alex63 in forum Qt Programming
    Replies: 2
    Last Post: 27th June 2006, 18:18
  2. string handling
    By vijay anandh in forum Qt Programming
    Replies: 4
    Last Post: 5th May 2006, 09:15
  3. Keyboard shortcuts problem.
    By Lemming in forum Qt Programming
    Replies: 4
    Last Post: 5th April 2006, 16:12
  4. Capture a keyboard event
    By mahe2310 in forum Qt Programming
    Replies: 8
    Last Post: 16th February 2006, 11:19
  5. Query keyboard state in Qt 3
    By Pieter from Belgium in forum Qt Programming
    Replies: 2
    Last Post: 9th February 2006, 17:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.