在使用 Qt 开发的媒体播放器中切换全屏
我目前正在使用 Qt 开发一个媒体播放器。所需的常见功能之一是能够切换全屏。
渲染画布本质上是一个 QGLWidget(我从它继承了子类)。它被添加到应用程序窗口,该窗口是该媒体播放器的主窗口。除了渲染画布之外,应用程序窗口还有工具栏、状态栏和其他小部件。我想要实现的全屏是让渲染画布占据全屏,而其他小部件不可见。同时,我仍然可以通过按键触发事件。
我尝试将渲染画布的父级重置为 0 并调用 showFullScreen() 函数。我在应用程序窗口上调用了 hide() 。这使得画布占据了整个屏幕,这是预期的。但是,应用程序没有捕获任何按键事件。结果,我无法恢复正常。另外,画布背景在黑色和白色之间闪烁(默认背景为白色)。
无论如何,我不认为我尝试过的方法是实现这一点的最佳方法。因为当我切换回正常状态时,将会发生一些复杂的重新调整。整个应用程序变得难以管理,因为全屏时需要执行一些任务,例如查看piexl值(源是原始的)。
有人能建议更好的方法来实现全屏切换吗?
I am currently developing a media player using Qt. One of the common features required is to be able to toggle full screen.
The rendering canvas essentially is a QGLWidget(I subclassed from it). It is added to a application window which is the main window for this media player. Besides the rendering canvas, the application window has toolbar, status bar and other small widgets. The full screen I want to implement is to make the rendering canvas occupying the full screen without other widgets being visible. Meanwhile, I can still trigger events by pressing keys.
I have tried reset the parent of the rendering canvas to 0 and call the showFullScreen() function. And I called the hide() on the application window. This makes the canvas occupy the entire screen which is expected. However, the application is not grabbing any key press event. As a result, I cannot get back to the normal. Plus, the canvas background is flashing between black and white(default background is white).
Anyways, I don't think the way I have tried is the best way to implement this. Since there will be some complex reparenting going on when I switch back to normal. And the whole application become hard to manage because there will be some tasks to be performed while being full screen such as viewing piexl values(the source is raw).
Can anybody suggest a better way to implement the toggling of full screen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是哪个版本?
我向您提出一个必须测试的解决方案。
当您想要全屏时,尝试复制您的内容(如果视频在小部件中,请打开一个新的 QWidget 并将内容复制到新的小部件),理论上您将拥有 2 个具有相同内容的小部件,但你不应该隐藏和缩小任何东西的大小。
告诉我它是否对你有用。
其次,看看这些帖子,可能有用:
最后,再读一遍,您可以错过了一些东西:/
http://doc.qt.io/qt-5/qwidget.html# showFullScreen
告诉我我是否误解了什么,或者是否有任何(以及什么)帮助。
Which version are you using ?
I propose you a solution you have to test.
When you want to fullscreen, try to make a copy of you content (if the video is in a widget, open a new QWidget and copy the content to the new widget), you'll in theory have 2 widgets with the same content, but you shouldn't have to hide and reduce size of anything.
Tell me if it worked for you.
Secondly, look at these post, could be usefull:
Finaly, read again, you could have missed something :/
http://doc.qt.io/qt-5/qwidget.html#showFullScreen
Tell me if I misunderstood something, or if anything (and what) helped.