gpt4 book ai didi

python - 为一堆标签化的 QDockWidgets 设置顶部 QDockWidget

转载 作者:行者123 更新时间:2023-12-04 03:09:10 28 4
gpt4 key购买 nike

H 在那里。

谁能告诉我如何设置标签化的 QDockWidget 弹出到前面(作为事件停靠栏)?

在下图中,“full”选项卡被选中并且它的内容可见,但我想将“mouth”选项卡设置为所选选项卡并使其内容可见。

tabs

代码:

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_()

最佳答案

一个标签化的 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_())

关于python - 为一堆标签化的 QDockWidgets 设置顶部 QDockWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7810021/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com