使用 PySide 的更多停靠位置? [英] More dock locations using PySide?

查看:65
本文介绍了使用 PySide 的更多停靠位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢码头的比喻,相信用户可能想要两个大的中央"小部件以及顶部、底部和侧面的小部件.我也喜欢带有标签的停靠小部件,例如QDockWidget("文件系统查看器").是否有一种简单的当前方法来添加更多停靠位置而不是单个中央小部件?该线程表明它曾经可用,但现在不推荐使用.如果没有,有没有办法标记中央小部件,使其看起来像码头?

I like the dock analogy and believe users may want two large "central" widgets as well as the top, bottom, and side widgets. I also like that the dock widgets are labeled, e.g. QDockWidget("File System Viewer"). Is there an easy, current way to add more dock locations instead of a single central widget? This thread suggests it was once available but is not recommended now. If not, is there a way to label the central widget so it looks like the docks?

推荐答案

您链接的答案已经提供了一个解决方案,即设置一个 QMainWindow 作为中央小部件.这个中央小部件必须只有停靠小部件,不能有自己的中央小部件.

The answer you linked to already provides a solution, which is to set a QMainWindow as the central widget. This central widget must only have dock widgets, and no central widget of its own.

这种方法有一些限制.首先,中央码头小部件不能与外部码头小部件互换(反之亦然).其次,如果所有外部停靠小部件都关闭了,除非主窗口有菜单栏,否则将无法恢复它们.菜单栏会自动提供用于恢复停靠小部件的上下文菜单.这与右键单击停靠小部件标题栏时显示的菜单相同.

There are a few limitations to this approach. Firstly, the central dock-widgets cannot be interchanged with the outer dock-widgets (and vice-versa). Secondly, if all the outer dock-widgets are closed, there will no way to restore them unless the main-window has a menu-bar. The menu-bar automatically provides a context menu for restoring dock-widgets. This is the same menu that is shown when right-clicking a dock-widget title-bar.

以下是演示此方法的演示脚本:

Here is a demo script that demonstrates this approach:

import sys
from PySide import QtGui, QtCore

class MainWindow(QtGui.QMainWindow):
    def __init__(self):
        super(MainWindow, self).__init__()
        self.centre = QtGui.QMainWindow(self)
        self.centre.setWindowFlags(QtCore.Qt.Widget)
        self.centre.setDockOptions(
            QtGui.QMainWindow.AnimatedDocks |
            QtGui.QMainWindow.AllowNestedDocks)
        self.setCentralWidget(self.centre)
        self.dockCentre1 = QtGui.QDockWidget(self.centre)
        self.dockCentre1.setWindowTitle('Centre 1')
        self.centre.addDockWidget(
            QtCore.Qt.LeftDockWidgetArea, self.dockCentre1)
        self.dockCentre2 = QtGui.QDockWidget(self.centre)
        self.dockCentre2.setWindowTitle('Centre 2')
        self.centre.addDockWidget(
            QtCore.Qt.RightDockWidgetArea, self.dockCentre2)
        self.dockLeft = QtGui.QDockWidget(self)
        self.dockLeft.setWindowTitle('Left')
        self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.dockLeft)
        self.dockRight = QtGui.QDockWidget(self)
        self.dockRight.setWindowTitle('Right')
        self.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.dockRight)
        self.menuBar().addMenu('File').addAction('Quit', self.close)

if __name__ == '__main__':

    app = QtGui.QApplication(sys.argv)
    window = MainWindow()
    window.setGeometry(500, 50, 600, 400)
    window.show()
    sys.exit(app.exec_())

这篇关于使用 PySide 的更多停靠位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆