为一堆选项卡化的 QDockWidget 设置顶部 QDockWidget

发布于 2024-12-10 20:28:39 字数 1345 浏览 2 评论 0原文

在那里。

有人可以告诉我如何设置一个选项卡式 QDockWidget 以弹出到前面(作为活动底座)吗?

在下图中,“完整”选项卡被选中,其内容可见,但我想将“嘴”选项卡设置为所选选项卡并使其内容可见。

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

H there.

Can someone please tell me how to set a tabbified QDockWidget to pop to the front (be the active dock)?

In the picture below, the "full" tab is selected and it's contents are visible but I want to set the "mouth" tab to the selected tab and have its contents visible.

tabs

Code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遗失的美好 2024-12-17 20:28:39

可以将选项卡式停靠小部件设置为所选选项卡,如下所示:

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

A tabified dockwidget can be set as the selected tab like this:

dockwidget.raise_()

EDIT

Here's a runnable example based on the code in the question:

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_())
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文