2012-10-31 26 views
2

multi dockpyqt:碼頭堆疊qdockwidgets側

我做了一個多碼頭窗口。要做到這一點,我隱藏了中心部件,並且我知道了。但是我有一個問題(或者更多的東西可能?)。如果碼頭小部件堆疊在另一個之上,我無法將碼頭部件停靠在他們的一側。如上圖所示,我只需停靠在碼頭之間。我該如何調整它?這是我的整個代碼。

from PyQt4 import QtCore, QtGui 

class Window(QtGui.QMainWindow): 
    def __init__(self): 
     QtGui.QMainWindow.__init__(self)   
     self.resize(800, 600) 
     self.setWindowTitle(QtGui.QApplication.translate("self", "self", None, QtGui.QApplication.UnicodeUTF8)) 
     self.setDockOptions(QtGui.QMainWindow.AnimatedDocks) 
     self.centralwidget = QtGui.QWidget(self) 
     self.centralwidget.hide() 
     self.setCentralWidget(self.centralwidget)   
     self.menubar = QtGui.QMenuBar(self) 
     self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21)) 
     self.setMenuBar(self.menubar) 
     self.statusbar = QtGui.QStatusBar(self) 
     self.setStatusBar(self.statusbar) 
     self.dock1Widget = QtGui.QDockWidget(self) 
     self.dock1Widget.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) 
     self.dock1Widget.setWindowTitle(QtGui.QApplication.translate("self", "dock1", None, QtGui.QApplication.UnicodeUTF8)) 
     self.dock1WidgetContents = QtGui.QWidget() 
     self.dock1Widget.setWidget(self.dock1WidgetContents) 
     self.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dock1Widget) 
     self.dock2Widget = QtGui.QDockWidget(self) 
     self.dock2Widget.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) 
     self.dock2Widget.setWindowTitle(QtGui.QApplication.translate("self", "dock2", None, QtGui.QApplication.UnicodeUTF8)) 
     self.dock2WidgetContents = QtGui.QWidget() 
     self.dock2Widget.setWidget(self.dock2WidgetContents) 
     self.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dock2Widget) 
     self.dock3Widget = QtGui.QDockWidget(self) 
     self.dock3Widget.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) 
     self.dock3Widget.setWindowTitle(QtGui.QApplication.translate("self", "dock3", None, QtGui.QApplication.UnicodeUTF8)) 
     self.dock3WidgetContents = QtGui.QWidget() 
     self.dock3Widget.setWidget(self.dock3WidgetContents) 
     self.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dock3Widget) 
     self.dock4Widget = QtGui.QDockWidget(self) 
     self.dock4Widget.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures) 
     self.dock4Widget.setWindowTitle(QtGui.QApplication.translate("self", "dock4", None, QtGui.QApplication.UnicodeUTF8)) 
     self.dock4WidgetContents = QtGui.QWidget() 
     self.dock4Widget.setWidget(self.dock4WidgetContents) 
     self.addDockWidget(QtCore.Qt.DockWidgetArea(1), self.dock4Widget) 

if __name__ == '__main__': 

    import sys 
    app = QtGui.QApplication(sys.argv) 
    window = Window() 
    window.show() 
    app.exec_() 

回答

2

沒有一個centralWidgetdockWidgetArea可以擴大一路,使所有其他停靠區域不可訪問。

一種可能的解決方案是使用嵌套的碼頭(AllowNestedDocks)。這將允許您更自由地堆疊碼頭小部件。這不完全相同的行爲,但可能更靈活。設置您的對接方案是這樣的:

self.setDockOptions(QtGui.QMainWindow.AnimatedDocks | QtGui.QMainWindow.AllowNestedDocks) 

順便說一句,如果你不想要一箇中央物件,你可以不設置它。默認值是NULL,這與設置虛擬小部件和隱藏具有相同的效果。

+0

謝謝您的建議。正如你所建議的,我重寫了我的代碼:) –