Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: Overlay

  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

    Question Overlay

    In my video player, I want to add an overlay so that I can click on the screen and put a red mark for each place I click on the screen. I originally thought a QCanvas could be used for this, but have discovered it has been taken out of Qt 4 and its replacement is not back in. So what can I use to do this? A QPixmap? Is this easy to do? Thanks for your help!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overlay

    It doesn't matter what will you choose to paint your marks. Eventually you'll have to use QPainter anyway. You can read in Qt Quarterly about different composition modes and how do they work.

  3. #3
    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: Overlay

    I know I want to use the QPainter class, but I can just make the QPixmap object transparent and use the QPainter object to draw my points onto my overlay, right? Also, how do I place the QPixmap over the desired spot that I want. I do not see a constructor that lets me associate it with a parent widget and I don't see a function to allow me to set its location. Thanks again for your help!

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overlay

    You don't. You have to draw it using QPainter::drawPixmap().

  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

    Default Re: Overlay

    All I want to do is draw a point over my video scene. I want the user to click on a spot on the video scene and draw a red dot over it. Can I create a transparent QPixmap to place over the video and draw this, and then call QPainter::drawPoint to draw the point, or do I somehow have to associate the point onto the QPixmap and then redraw the QPixmap? Thanks again!!

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overlay

    Just prepare your pixmap and draw it. You can either use a premade pixmap or draw on it in your application.

  7. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Overlay

    Your video player is inside a QAxWidget right?
    Depending a bit on the purpose of the "red points", I would probably subclass the QAxWidget, add a list of points as a member variable and reimplement a few methods:
    - mouse press/release event: for adding the clicked point to the list
    - paint event: for drawing all the points in the list, AFTER calling the base class implementation
    J-P Nurmi

  8. #8
    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

    Default Re: Overlay

    Yes my videoplayer is inside a QAxWidget. The users will only be putting 1-2 red dots on per frame, and when I move frames I need to reset the overlay to transparent and add any existing red points already clicked on for that frame. I am using a vector to keep track of the points that are being clicked on since I have no idea how long the video may be or how many times the user may click on one frame. So I am capturing the mouse clicks already. But I don't understand how I draw. Wysota mentioned the drawPixmap() but I am confused about this. I don't know if a QPixmap is the way to go, it was just something I saw and thought might work. I created a pointer to a QPixmap and initialized it and set its fill to Qt::transparent, but then should the QPainter object be initialized as new QPainter( this ) or QPainter( QPixmapObject )? I thought I could then just use QPainter's drawPoint function to add the new point that was clicked on. So am I misunderstanding something or what? As you can tell, I am very confused on how to go about this stuff. I have no file that contains a transparent image for QPixmap. I am just wanting to create a brand new transparent file instead of referencing one by a path. Thanks again!

  9. #9
    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

    Question Re: Overlay

    Any ideas why I get this error in VS.Net VC++ 7?

    In my .h file I say

    Qt Code:
    1. QPixmap *mpOverlay;
    To copy to clipboard, switch view to plain text mode 

    In my .cpp file I say this to initialize my stuff:

    Qt Code:
    1. mpOverlay = new QPixmap( 561, 351 );
    2. mpOverlay->fill( Qt::transparent );
    3.  
    4. mpVideoPainter = new QPainter( this );
    5. mpVideoPainter->setPen( Qt::red );
    6.  
    7. QRectF target( 10.0, 41.0, 561.0, 351.0 );
    8. QRectF source( 0.0, 0.0, 551.0, 310.0 );
    9.  
    10. mpVideoPainter->drawPixmap( target, &mpOverlay, source );
    To copy to clipboard, switch view to plain text mode 


    But I get this error when I compile: error C2664: 'void QPainter::drawPixmap(const QRectF &,const QPixmap &,const QRectF &)' : cannot convert parameter 2 from 'QPixmap **__w64 ' to 'const QPixmap &'

    I have googled for solutions but cannot seem to find any. I believe my arguments are correct. Thanks!
    Last edited by ToddAtWSU; 17th May 2006 at 18:08.

  10. #10
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Overlay

    Quote Originally Posted by ToddAtWSU
    But I get this error when I compile: error C2664: 'void QPainter::drawPixmap(const QRectF &,const QPixmap &,const QRectF &)' : cannot convert parameter 2 from 'QPixmap **__w64 ' to 'const QPixmap &'
    That should be:
    Qt Code:
    1. mpVideoPainter->drawPixmap( target, *mpOverlay, source );
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  11. The following user says thank you to jpn for this useful post:

    ToddAtWSU (17th May 2006)

  12. #11
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Overlay

    Here's a one solution for you to consider:

    Qt Code:
    1. class Player: public QAxWidget
    2. {
    3. ...
    4. private:
    5. // a 2-dimensional vector; "a vector of points for each frame"
    6. QVector< QVector<QPoint> > framePoints;
    7. };
    8.  
    9. void Player::paintEvent(QPaintEvent* e)
    10. {
    11. // let the activex control to draw itself underneath
    12. QAxWidget::paintEvent(e);
    13.  
    14. // initialize a painter
    15. QPainter painter(this);
    16. painter.setPen(QPen(Qt::red)); // red
    17.  
    18. // draw all the points stored for the current frame directly on the widget
    19. foreach (QPoint pt, framePoints.at(currentFrame))
    20. painter.drawPoint(pt);
    21. }
    To copy to clipboard, switch view to plain text mode 
    J-P Nurmi

  13. #12
    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

    Default Re: Overlay

    I am not sure why putting the * in front helps. To me that turns the pointer into a pointer to a pointer, but for some reason it works. I thought the function wanted my argument de-referenced, but I guess not. So why when I change the Pixmaps fill color to say green do I not see a green rectangle appear over my video player? Thanks again!

  14. #13
    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

    Default Re: Overlay

    When I call the drawPoint function, I see nothing appear on my screen. I clicked around 15-20 times on one frame just to see if anything would appear and I do not see anything. Mine looks slightly like this where mpVideoPlayer is my QAxWidget and AzElPoint is a struct with an xPos, yPos, and frameNumber and azElPoints is a vector of these:

    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. // Mouse Button Release handlers
    9. if( event->type() == QEvent::MouseButtonRelease )
    10. {
    11. AzElPoint point;
    12. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
    13.  
    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. azElPoints.push_back( point );
    23. printf( "x=%d, y=%d\n", point.xPos, point.yPos );
    24. mpVideoPainter->drawPoint( point.xPos, point.yPos );
    25.  
    26. return true;
    27. }
    28. else if( mouseEvent->button() == Qt::RightButton )
    29. {
    30. // If right button, remove any point located in current frame
    31. azElPoints.push_back( point );
    32. printf( "x=%d, y=%d\n", point.xPos, point.yPos );
    33.  
    34. return true;
    35. }
    36. }
    37. }
    38.  
    39. if( event->type() == QEvent::Paint || event->type( ) == QEvent::Move )
    40. {
    41. if( pMediaSeeking != NULL )
    42. {
    43. repaintWindow( );
    44. QPainter painter( mpVideoPlayer );
    45. painter.setPen( QPen( Qt::red ) );
    46. for( int i = 0 ; i < azElPoints.size( ) ; i++ )
    47. {
    48. if( azElPoints[i].frameNumber == getCurrentFrame( ) )
    49. {
    50. painter.drawPoint( azElPoints[i].xPos, azElPoints[i].yPos );
    51. }
    52. }
    53. }
    54. }
    55.  
    56. return QObject::eventFilter( obj, event );
    57. }
    To copy to clipboard, switch view to plain text mode 

    The repaintWindow( ) function looks like this but it is mainly ActiveX functions and calls so I will not include it since it has nothing to do with Qt. pMediaSeeking being NULL means a video is not playing and we do not need to worry about repainting it or collecting data on it. I also haven't worried about implementing the right-button events yet assuming it will be fairly similar to the left-click events. Thanks once again for your help!!
    Last edited by ToddAtWSU; 17th May 2006 at 18:41.

  15. #14
    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: Overlay

    Is using an eventFilter the wrong way to go about this? Should I create a separate PaintEvent function? Thanks again. I thought this should draw the point, but unfortunately it does not.

  16. #15
    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 Re: Overlay

    I added an update( ) call to the if-statement that says:

    Qt Code:
    1. if( mouseEvent->button() == Qt::LeftButton )
    2. { // If left button, place mark on overlay to indicate position
    3. // and store position in array at the current frame index
    4. azElPoints.push_back( point );
    5. printf( "x=%d, y=%d\n", point.xPos, point.yPos );
    6. mpVideoPainter->drawPoint( point.xPos, point.yPos );
    7. return true; }
    To copy to clipboard, switch view to plain text mode 

    But now my video repaints and then right after that the points redraw, but not over the video. The video disappears. Any ideas how to keep the video showing while also showing the newly clicked point? Thanks for your help!
    Last edited by ToddAtWSU; 22nd May 2006 at 14:06.

  17. #16
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Overlay

    What does repaintWindow() do? Btw, you can paint only in paint events, not in move events.
    Assure that the video player gets drawn first, then draw your dots, and return true (so the paint event won't reach the video player).
    J-P Nurmi

  18. #17
    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: Overlay

    My repaintWindow( ) function is a function full of DirectShow/ActiveX calls. This is why I haven't worried about posting it here. It just redraws the current frame of the video into my QAxWidget, but since it is Microsoft-based it takes many calls to get it to work. What do you mean I can't paint in move events. If I move the video player, I want to be able to redraw the video and then redraw the point(s) on top of the video. My eventHandler looks like this:

    Qt Code:
    1. bool VideoViewerWindow::eventFilter( QObject *obj, QEvent *event )
    2. {
    3. if( obj == mpVideoPlayer )
    4. {
    5. // Mouse Button Release handlers
    6. if( event->type() == QEvent::MouseButtonRelease )
    7. {
    8. AzElPoint point;
    9. QMouseEvent *mouseEvent = static_cast<QMouseEvent *>(event);
    10.  
    11. point.frameNumber = getCurrentFrame( );
    12. point.xPos = mouseEvent->x( );
    13. point.yPos = mouseEvent->y( );
    14.  
    15. if( mouseEvent->button() == Qt::LeftButton )
    16. {
    17. // If left button, place mark on overlay to indicate position
    18. // and store position in array at the current frame index
    19. azElPoints.push_back( point );
    20. printf( "x=%d, y=%d\n", point.xPos, point.yPos );
    21. update( );
    22.  
    23. return true;
    24. }
    25. else if( mouseEvent->button() == Qt::RightButton )
    26. {
    27. // If right button, remove any point located in current frame
    28. azElPoints.push_back( point );
    29. printf( "x=%d, y=%d\n", point.xPos, point.yPos );
    30.  
    31. return true;
    32. }
    33. }
    34. }
    35.  
    36. if( event->type() == QEvent::Paint || event->type( ) == QEvent::Move )
    37. {
    38. if( pMediaSeeking != NULL )
    39. {
    40. repaintWindow( );
    41. QPainter* painter;
    42. painter = new QPainter( mpVideoPlayer );
    43. painter->setPen( QPen( Qt::red, 3 ) );
    44. for( int i = 0 ; i < azElPoints.size( ) ; i++ )
    45. {
    46. if( azElPoints[i].frameNumber == getCurrentFrame( ) )
    47. {
    48. painter->drawPoint( azElPoints[i].xPos, azElPoints[i].yPos );
    49. }
    50. }
    51. delete painter;
    52. return true;
    53. }
    54. }
    55.  
    56. return QObject::eventFilter( obj, event );
    57. }
    To copy to clipboard, switch view to plain text mode 

    So what am I doing wrong? To me, it seems to draw the window and then draw the points but erasing the video since I am drawing the points right onto the QAxWidget. So do I need to draw this on a transparent overlay? I quickly see the video and then all I see is the brown background of the main Qt App and the red dot(s) that have been drawn. Thanks!
    Last edited by ToddAtWSU; 22nd May 2006 at 14:32.

  19. #18
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Overlay

    Which Qt4 release are you using?

  20. #19
    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

    Default Re: Overlay

    I am using version 4.1.0.

  21. #20
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Overlay

    Quote Originally Posted by ToddAtWSU
    What do you mean I can't paint in move events. If I move the video player, I want to be able to redraw the video and then redraw the point(s) on top of the video.
    From QPainter docs:
    Warning: Unless a widget has the Qt::WA_PaintOutsidePaintEvent attribute set. A QPainter can only be used on a widget inside a paintEvent() or a function called by a paintEvent(). On Mac OS X, you can only paint on a widget in a paintEvent() regardless of this attribute's setting.
    You could just call update() to schedule a paint event and draw there. You should actually get a warning output in the console if you try to use a QPainter on a widget outside paint event.

    This might need some tweaking but you could try something like this:
    Qt Code:
    1. if( event->type( ) == QEvent::Move )
    2. {
    3. // just call update() to schedule a paint event
    4. update();
    5. }
    6. else if( event->type() == QEvent::Paint )
    7. {
    8. if( pMediaSeeking != NULL )
    9. {
    10. repaintWindow( );
    11.  
    12. // remove the event filter during sending
    13. // the paint event to avoid an infinite loop
    14. mpVideoPlayer->removeEventFilter(this);
    15.  
    16. // send the event and let the video player to draw itself first
    17. QApplication::sendEvent(mpVideoPlayer, event);
    18.  
    19. // restore the event filter
    20. mpVideoPlayer->installEventFilter(this);
    21.  
    22. // draw your dots over the video player
    23. QPainter painter( mpVideoPlayer );
    24. painter.setPen(...);
    25. ....
    26.  
    27. // be sure to return true so that the video player doesn't
    28. // receive this paint event and paint itself over again
    29. return true;
    30. }
    31. }
    To copy to clipboard, switch view to plain text mode 
    Would've been a bit easier if you had just subclassed in the first place..
    J-P Nurmi

Similar Threads

  1. QtWidget in Overlay Planes on Windows OpenGL
    By IVTdeveloper in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2008, 11:00
  2. QGLWidget with overlay
    By pandora-qt in forum Qt Programming
    Replies: 0
    Last Post: 29th February 2008, 10:44
  3. QScrollView Overlay
    By EricTheFruitbat in forum Qt Programming
    Replies: 5
    Last Post: 27th December 2006, 09:29
  4. Adding Rectangular overlay on graphics view
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2006, 19:42
  5. Pixmap Overlay
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 22nd June 2006, 20:19

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.