简体   繁体   English

在Qt Widget中的视频上绘画

[英]Painting on top of video in a Qt Widget

I am developing a Qt application that can play the videos and shows some scrolling bar along the way. 我正在开发一个可以播放视频的Qt应用程序,并在此过程中显示一些滚动条。 The window size MUST Not exceed the limit of 720px in height and 1280 in width. 窗口尺寸不得超过720px的高度和1280的宽度。 I use MPlayer as a slave process and pass it the winId() of the QWidget and it renders the video in it. 我使用MPlayer作为从属进程并将其传递给QWidget的winId()并将视频呈现在其中。 Now I want another widget on top of this video widget to show some results all the time but placing a label widget on top of the widget that contains video does not serve the purpose as it gets painted over and over by the video. 现在我希望在此视频窗口小部件之上的另一个窗口小部件始终显示一些结果,但是在包含视频的窗口小部件顶部放置标签窗口小部件不能达到目的,因为它会被视频反复绘制。 Any workaround? 任何解决方法? Suggestions about it? 关于它的建议?

When using MPlayer in this manner, I believe your best option would be to create a second window . 当以这种方式使用MPlayer时,我相信您最好的选择是创建第二个窗口

There's a couple ways you could go from here, the fancier way which might not work on some versions/configurations of Xorg is to have the second window the same size as the first, and place it directly on top of the other (with a mechanism to move the other window when either is moved), and make the window transparent except for your controls (transparency being the problem with some versions of X, check labs.trolltech.com for some examples of this). 有几种方法你可以从这里开始,在一些版本/配置的Xorg上可能不起作用的更好的方法是让第二个窗口与第一个窗口的大小相同,并将它直接放在另一个窗口的上面(带有一个机制)移动另一个窗口时,移动其他窗口,并使窗口透明,除了你的控件(透明度是某些版本的X的问题,检查labs.trolltech.com的一些例子)。

The alternative method, which I believe is what VLC uses when in fullscreen mode, is to have the second window just be a small little thing with the controls, and position it on top of the first window with an offset and no border... making it so when the first window is moved, the second window's position is updated. 另一种方法,我相信VLC在全屏模式下使用的方法是让第二个窗口只是控件的一个小东西,并将它放在第一个窗口的顶部,带有偏移,没有边框......当第一个窗口移动时,第二个窗口的位置会更新。

I suggest you look into the Phonon framework for playing the video. 我建议你看一下播放视频的Phonon框架。 It should handle the playing without calling a separate executable, which would likely solve the painting problem. 它应该处理播放而不调用单独的可执行文件,这可能会解决绘画问题。

Encapsulate your video in a widget, emitting a QImage into a slot that converts it into a QPixmap which you paint on the widget during overridden paintEvent(). 将视频封装在窗口小部件中,将QImage发送到插槽中,将其转换为QPixmap,在覆盖的paintEvent()期间在窗口小部件上绘制。

I don't know what kind of interaction you have to provide with your videos other than "a message" but if you want something fancy, QGraphicsView can provide a lot of these effects for you. 我不知道你的视频除了“消息”之外还要提供什么样的互动,但如果你想要一些奇特的东西,QGraphicsView可以为你提供很多这些效果。

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM