Qt WA_TranslucentBackground 导致视频渲染不了的问题
使用QT5.7 + VS2015做的試驗,視頻渲染使用D3D9。發現的規律是:
頂層窗口(指父窗口為NULL的窗口)如果設置了
this->setWindowFlags( Qt::FramelessWindowHint);this->setAttribute(Qt::WA_TranslucentBackground,true);那么不管是用該頂層窗口本身的窗口句柄,還是使用子窗口的句柄作為D3D的渲染窗口,都渲染不出來。如果頂層窗口沒有同時設置以上的屬性/標志,子窗口不管設置還是沒有設置以上兩個屬性/標志,視頻都可以渲染出來。
調試了下,D3D的初始化、渲染接口都能成功執行,找了不少論壇,后來在一個頁面上看到有類似的說明:
OpenGL_and_translucent_background_do_not_work_together_due_to_a_limitation
里面提到:
Due to a limitation in window managers, it is not possible to combine OpenGL with a translucent background window (set with WA_TranslucentBackground). The reason for this is because OpenGL is rendered directly onto the screen and the compositor used to enable the translucent background cannot ensure that the OpenGL is rendered correctly.
There is nothing that can be done in Qt to fix this as it needs to be done on the side of the window manager.
To work around this issue you can either just use Qt to render everything and not OpenGL, or you can render the OpenGL into a pixmap and draw that onto your widget instead.
大意是OpenGL是直接渲染在屏幕的,而透明背景的compositor不能保證OpenGL可以正確地渲染,我想D3D也是一樣的原理,直接訪問顯卡,所以D3D在這種情況下不能渲染視頻,估計也是這個原因,它里面還提到了對于這個問題Qt做不了什么,因為這需要窗口管理器那邊來解決這個問題。
我又嘗試了使用Dib來貼圖,仍然失敗。看來目前還未有解決辦法。
總結
以上是生活随笔為你收集整理的Qt WA_TranslucentBackground 导致视频渲染不了的问题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 基于J2EE的B2C电子商务系统开发与实
- 下一篇: 快看看——刚出生的小刺猬,超可爱{图}