Results 1 to 20 of 22

Thread: Overlay

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.

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

    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!

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

    Default Re: Overlay

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

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

    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!!

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    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.

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

    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

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

    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!

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

    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 19:08.

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

    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

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

    ToddAtWSU (17th May 2006)

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

    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

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

    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!

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

    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 19:41.

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

    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.

  15. #14
    Join Date
    Jan 2006
    Location
    Mountain View, CA
    Posts
    279
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows
    Thanked 42 Times in 37 Posts

    Default Re: Overlay

    Quote Originally Posted by ToddAtWSU
    I am not sure why putting the * in front helps.
    It helps because you are now giving it the argument type that it is expecting rather than the argument type that it is not expecting.

    To me that turns the pointer into a pointer to a pointer
    No, that de-references the pointer. See any docs on C/C++ to see the meaning of the '*' operator.

    I thought the function wanted my argument de-referenced, but I guess not.
    The function wants a reference to a QPixmap object, nothing more. Whether that means de-referencing your variable depends on what kind of object you are dealing with, a QPixmap or a 'pointer to QPixmap'. The following should show you how to correctly deal with both cases.

    Example 1 - QPixmap allocated on the stack.
    Qt Code:
    1. mOverlay = QPixmap( 561, 351 );
    2. ...
    3. mpVideoPainter->drawPixmap( target, mOverlay, source );
    To copy to clipboard, switch view to plain text mode 

    Example 2 - QPixmap allocated on the heap.
    Qt Code:
    1. mpOverlay = new QPixmap( 561, 351 );
    2. ...
    3. mpVideoPainter->drawPixmap( target, *mpOverlay, source );
    To copy to clipboard, switch view to plain text mode 
    Last edited by Chicken Blood Machine; 22nd May 2006 at 23:02.
    Save yourself some pain. Learn C++ before learning Qt.

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

    Default Re: Overlay

    I don't know what I was thinking, must have been having a brain freeze at that point. I have been working with C/C++ for 4+ years now, but for some reason I was thinking the & and the * were backwards when I was working on that. Probably too much programming and not enough sunlight.

Similar Threads

  1. QtWidget in Overlay Planes on Windows OpenGL
    By IVTdeveloper in forum Qt Programming
    Replies: 2
    Last Post: 20th August 2008, 12:00
  2. QGLWidget with overlay
    By pandora-qt in forum Qt Programming
    Replies: 0
    Last Post: 29th February 2008, 11:44
  3. QScrollView Overlay
    By EricTheFruitbat in forum Qt Programming
    Replies: 5
    Last Post: 27th December 2006, 10:29
  4. Adding Rectangular overlay on graphics view
    By forrestfsu in forum Qt Programming
    Replies: 10
    Last Post: 21st November 2006, 20:42
  5. Pixmap Overlay
    By ToddAtWSU in forum Qt Programming
    Replies: 5
    Last Post: 22nd June 2006, 21: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
  •  
Qt is a trademark of The Qt Company.