2012-02-17 95 views
1

我想知道如何將聲子播放器設置爲全屏? 即時通訊使用此代碼。pyQT聲音播放器全屏?

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

,但我不斷收到此錯誤消息

TypeError: 'sip.methoddescriptor' object is not callable

上面的代碼工作是從一個樣本項目。原代碼是

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

即時通訊重新創建它在PyQT中,它似乎很難。 任何人都可以請指導我什麼即時消失(有一個預感) 或什麼即時做錯了?

+0

這可能不是但是如果您使用Wing IDE或Pycharm,則可以使用調試器和交互式控制檯輕鬆調試並查看確切的線路和問題以及導致該問題的對象。通常爲我隱式解決這類問題 – 2015-11-25 20:46:44

回答

2

一個VideoPlayer是不一樣的事,作爲一個VideoWidget

VideoPlayerQWidget一個子類,所以它isFullScreen方法 - 但它不會有方法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() 
+0

這是偉大的。它絕對有效!感謝ekhumoro。只是一個後續問題。我設法使它成爲全屏模式。有任何提示我如何退出它?因爲它的全屏。我不能按下按鈕激活全屏模式...再次感謝! – Katherina 2012-02-20 02:17:49

+0

@Katherina。查看我更新的答案以獲取退出全屏模式的方法。 – ekhumoro 2012-02-20 04:42:40

+0

非常感謝你給我這個詳細的樣品。 – Katherina 2012-02-20 05:44:48

0

我認爲問題在於你使用的是self.ui.videoPlayer.isFullScreen,它可能返回True或False,當你使用self.ui.videoPlayer.isFullScreen()時真的會解決爲'False()'。

奇怪的是,PyQT documentation甚至沒有列出'isFullScreen'作爲可用方法/屬性的一部分。但QWidget documentation顯示isFullScreen返回布爾值。

相反,試試這個:

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

嗨,我試着給你答案..我得到一個錯誤「」self.ui.videoPlayer.exitFullScreen() TypeError:'sip.methoddescriptor'對象不可調用。即時通訊仍然試圖解決這個合成器pyll – Katherina 2012-02-20 02:13:22