Results 1 to 2 of 2

Thread: Flicker Problem

  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

    Cool Flicker Problem

    I figured out how to get my overlay to work on my DirectShow video. I just made a QPixmap of size 5x5 and put this on a QLabel of size 5x5 which I draw on top of the QAxWidget displaying my video. This works great instead of trying to create a transparent pixmap/label but I get a lot of flicker when I click on the video to draw the point. In my GUI building function I set these variables up like this:

    Qt Code:
    1. mpOverlay = new QPixmap( 5, 5 );
    2. mpOverlay->fill( Qt::red );
    3.  
    4. mpOverlayLabel = new QLabel( mpVideoPlayer );
    5. mpOverlayLabel->setGeometry( QRect( 0, 0, 5, 5 ) );
    6. mpOverlayLabel->hide( );
    7. mpOverlayLabel->setPixmap( *mpOverlay );
    To copy to clipboard, switch view to plain text mode 

    Then whenever I click on the screen I do this:

    Qt Code:
    1. if( event->type() == QEvent::MouseButtonRelease )
    2. {
    3. AzElPoint point;
    4. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
    5.  
    6. point.frameNumber = getCurrentFrame( );
    7. point.xPos = mouseEvent->x( );
    8. point.yPos = mouseEvent->y( );
    9.  
    10. if( mouseEvent->button() == Qt::LeftButton )
    11. {
    12. // If left button, place mark on overlay to indicate position
    13. // and store position in array at the current frame index
    14. for( int i = 0 ; i < azElPoints.size( ) ; i++ )
    15. {
    16. if( azElPoints[i].frameNumber == getCurrentFrame( ) )
    17. {
    18. azElPoints.removeAt( i );
    19. erasePoint = true;
    20. }
    21. }
    22. azElPoints.push_back( point );
    23. printf( "x=%d, y=%d\n", point.xPos, point.yPos );
    24. update( );
    25. return true;
    26. }
    27. }
    To copy to clipboard, switch view to plain text mode 

    And my paint event handler just calls repaintWindow( ) which looks like this:

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

    You can see what I am doing is just showing/hiding the QLabel and then redrawing the video (ie. the QAxWidget) which in turns redraws the QLabel since it is a child of the QAxWidget. But when I click the screen, I want the dot (QPixmap/QLabel) to appear without causing the entire screen to flicker. Sometimes the screen flickers and sometimes it does not. And when it does flicker, sometimes the flicker lasts almost a half of a second - which is very noticeable. So any ideas on how to improve my function(s) to prevent this from flickering would be great! 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

    Smile Re: Flicker Problem

    I got the flickering disappearing because I was noticing that I was calling update() and there seemes to be another update() being called so I was redrawing the same thing twice. By taking out my update() call it took out the flicker. The only problem now is there is considerable lag between clicking on the screen and the small QLabel/QPixmap actually appearing. Is there just a big lag between catching the mouseButtonRelease and Paint event? The image clicking occurs fast and if I play the movie straight through after rewinding it after clicking on it, it plays through fast and shows all the points. So it seems the individual events work fast but when you combine them they are slow. Is this normal? Thanks!

Similar Threads

  1. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  2. Problem with receiving events from QDateEdit
    By gunhelstr in forum Qt Programming
    Replies: 4
    Last Post: 20th April 2006, 11:21
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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.