PyQt提供了方便的停靠窗口控件,咱們能夠很方便的編寫一個停靠窗口,代碼和效果以下:app
# -*- coding: utf-8 -*-
from PyQt4 import QtGui, QtCore
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.createDockWindows()
def createDockWindows(self):
dock1 = QtGui.QDockWidget('Tab1', self)
dock1.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea|QtCore.Qt.RightDockWidgetArea)
widget1 = QtGui.QWidget(parent=dock1)
dock1.setWidget(widget1)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock1)
dock2 = QtGui.QDockWidget('Tab2', self)
dock2.setAllowedAreas(QtCore.Qt.LeftDockWidgetArea|QtCore.Qt.RightDockWidgetArea)
widget2 = QtGui.QWidget(parent=dock1)
dock2.setWidget(widget2)
self.addDockWidget(QtCore.Qt.RightDockWidgetArea, dock2)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())
這時若是想把這兩個停靠窗口疊加到一塊兒,怎麼辦?那就要用到QMainWindow.tabifyDockWidget (self, QDockWidget, QDockWidget)方法,咱們加一行代碼看看:ui
self.tabifyDockWidget(dock1, dock2)
這時的問題是Tab2是當前的標籤頁,通常按習慣來說,默認第一個是當前標籤頁,這時候就須要用到QWidget.raise_(self)方法,該方法能夠把本身提高到其父控件頂層。blog
再加一行代碼:utf-8
dock1.raise_()
get