那里。
有人可以告诉我如何设置一个标签化的QDockWidget弹出到前面(是活动的底座)吗?
在下图中,选中了“完整”标签,其内容可见,但我想将“嘴”标签设置为所选标签,并使其内容可见。
self.dockList = []
approvedAdded = False
# add new dock widgets
for dockName in previewDict.keys():
previewList = previewDict[ dockName ]
# setup dock
dock = QDockWidget( dockName )
dock.setWidget( PreviewWidget( previewList ) )
dock.setAllowedAreas( Qt.TopDockWidgetArea )
dock.setFeatures( QDockWidget.DockWidgetMovable | QDockWidget.DockWidgetFloatable )
# add to ui
self.addDockWidget( Qt.TopDockWidgetArea , dock )
# add to list
insertIndex = len( self.dockList ) - 1
if dockName == "approved":
insertIndex = 0
approvedAdded = True
elif dockName == tfPaths.user():
if not approvedAdded:
insertIndex = 0
else:
insertIndex = 1
self.dockList.insert( insertIndex , dock )
# tabify dock widgets
if len( self.dockList ) > 1:
for index in range( 0 , len(self.dockList) - 1 ):
self.tabifyDockWidget( self.dockList[index] , self.dockList[index + 1] )
# set tab at pos [0] in list to active
if self.dockList:
print self.dockList[0].windowTitle()
self.dockList[0].raise_()
答案 0 :(得分:2)
可以将列表化的dockwidget设置为所选选项卡,如下所示:
dockwidget.raise_()
修改强>
这是一个基于问题代码的可运行示例:
from PyQt4 import QtCore, QtGui
class Window(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setWindowTitle('Dock Widgets')
self.button = QtGui.QPushButton('Raise Next Tab', self)
self.button.clicked.connect(self.handleButton)
self.setCentralWidget(self.button)
self.dockList = []
approvedAdded = False
for dockName in 'Red Green Yellow Blue'.split():
dock = QtGui.QDockWidget(dockName)
dock.setWidget(QtGui.QListWidget())
dock.setAllowedAreas(QtCore.Qt.TopDockWidgetArea)
dock.setFeatures(QtGui.QDockWidget.DockWidgetMovable |
QtGui.QDockWidget.DockWidgetFloatable)
self.addDockWidget(QtCore.Qt.TopDockWidgetArea, dock)
insertIndex = len(self.dockList) - 1
if dockName == 'Green':
insertIndex = 0
approvedAdded = True
elif dockName == 'Yellow':
if not approvedAdded:
insertIndex = 0
else:
insertIndex = 1
self.dockList.insert(insertIndex, dock)
if len(self.dockList) > 1:
for index in range(0, len(self.dockList) - 1):
self.tabifyDockWidget(self.dockList[index],
self.dockList[index + 1])
self.dockList[0].raise_()
self.nextindex = 1
def handleButton(self):
self.dockList[self.nextindex].raise_()
self.nextindex += 1
if self.nextindex > len(self.dockList) - 1:
self.nextindex = 0
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.show()
sys.exit(app.exec_())