pyQT声子播放器全屏显示?

发布于 2025-01-07 06:10:35 字数 569 浏览 0 评论 0原文

我想知道如何将声子播放器设置为全屏? 我正在尝试这个代码。

    if not self.ui.videoPlayer.isFullScreen():
        self.ui.videoPlayer.enterFullScreen()
    else: 
        self.ui.videoPlayer.exitFullScreen()

但我不断收到此错误消息

类型错误:“sip.methoddescriptor”对象不可调用

上面的代码来自示例项目。原始代码是

def full(self):
    if not self.videoWidget.isFullScreen():
        self.videoWidget.enterFullScreen()
    else: 
        self.videoWidget.exitFullScreen()

我在 PyQT 中重新创建的,这对我来说似乎很难。 谁能指导我缺少什么(有预感) 或者我做错了什么?

i was wondering how to set a phonon player to full screen?
im trying this codes.

    if not self.ui.videoPlayer.isFullScreen():
        self.ui.videoPlayer.enterFullScreen()
    else: 
        self.ui.videoPlayer.exitFullScreen()

but i keep on getting this error message

TypeError: 'sip.methoddescriptor' object is not callable

the code above works is from a sample project. the original code was

def full(self):
    if not self.videoWidget.isFullScreen():
        self.videoWidget.enterFullScreen()
    else: 
        self.videoWidget.exitFullScreen()

im recreating it in PyQT and it seems hard for me.
can anyone please guide me on what im missing(having a hunch about it)
or what im doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

極樂鬼 2025-01-14 06:10:35

VideoPlayerVideoWidget

VideoPlayerQWidget 的子类,因此它有一个 isFullScreen 方法 - 但它赢了' t有方法enterFullScreenexitFullScreen,它们属于VideoWidget类。

但是, VideoPlayer 类有一个 videoWidget 方法返回它使用的视频小部件的实例,因此您的代码示例可能应更改为:

videoWidget = self.ui.videoPlayer.videoWidget()
if videoWidget.isFullScreen():
    videoWidget.exitFullScreen()
else: 
    videoWidget.enterFullScreen()

编辑

要提供退出全屏模式的方法,请设置键盘快捷键:

class MainWindow(QtGui.QMainWindow):
    def __init__(self)
        ...
        self.shortcutFull = QtGui.QShortcut(self)
        self.shortcutFull.setKey(QtGui.QKeySequence('F11'))
        self.shortcutFull.setContext(QtCore.Qt.ApplicationShortcut)
        self.shortcutFull.activated.connect(self.handleFullScreen)

    def handleFullScreen(self):
        videoWidget = self.ui.videoPlayer.videoWidget()
        if videoWidget.isFullScreen():
            videoWidget.exitFullScreen()
        else: 
            videoWidget.enterFullScreen()

A VideoPlayer is not the same thing as a VideoWidget.

VideoPlayer is a subclass of QWidget, so it will have an isFullScreen method - but it won't have the methods enterFullScreen and exitFullScreen, which belong to the VideoWidget class.

However, the VideoPlayer class has a videoWidget method which returns the instance of the video widget it uses, so your code example should probably be changed to:

videoWidget = self.ui.videoPlayer.videoWidget()
if videoWidget.isFullScreen():
    videoWidget.exitFullScreen()
else: 
    videoWidget.enterFullScreen()

EDIT

To provide a method for exiting fullscreen mode, set up a keyboard shortcut:

class MainWindow(QtGui.QMainWindow):
    def __init__(self)
        ...
        self.shortcutFull = QtGui.QShortcut(self)
        self.shortcutFull.setKey(QtGui.QKeySequence('F11'))
        self.shortcutFull.setContext(QtCore.Qt.ApplicationShortcut)
        self.shortcutFull.activated.connect(self.handleFullScreen)

    def handleFullScreen(self):
        videoWidget = self.ui.videoPlayer.videoWidget()
        if videoWidget.isFullScreen():
            videoWidget.exitFullScreen()
        else: 
            videoWidget.enterFullScreen()
我ぃ本無心為│何有愛 2025-01-14 06:10:35

我认为问题是您使用 self.ui.videoPlayer.isFullScreen ,它可能返回 True 或 False,当您使用 self.ui.videoPlayer.isFullScreen() 时实际上解析为“False()”。

奇怪的是,PyQT 文档 没有甚至将“isFullScreen”列为可用方法/属性的一部分。但是 QWidget 文档 确实显示 isFullScreen 作为返回一个布尔值。

相反,试试这个:

if not self.ui.videoPlayer.isFullScreen:
    self.ui.videoPlayer.enterFullScreen()
else: 
    self.ui.videoPlayer.exitFullScreen()

I think the problem is your use of self.ui.videoPlayer.isFullScreen, it's probably returning True or False, which when you use self.ui.videoPlayer.isFullScreen() is really resolving down to 'False()'.

Oddly enough, the PyQT documentation doesn't even list 'isFullScreen' as part of the available, methods/properties. However the QWidget documentation does show isFullScreen as returning a boolean.

Instead, try this:

if not self.ui.videoPlayer.isFullScreen:
    self.ui.videoPlayer.enterFullScreen()
else: 
    self.ui.videoPlayer.exitFullScreen()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文