gpt4 book ai didi

python - PyQt4 : Connect splitter

转载 作者:太空宇宙 更新时间:2023-11-03 15:45:14 25 4
gpt4 key购买 nike

我想连接分离器以在 4 个小部件之间创建一个“交叉”分离器。我尝试使用两个分离器之间的信号和槽来做到这一点,即使没有发生错误,行为也不是我希望的(事实上什么也没有发生)。

import sys
from PyQt4 import QtGui, QtCore

class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.initUI()

self.window.setFocus()
self.setCentralWidget(self.window)
self.showMaximized()

def initUI(self) :
self.window = QtGui.QWidget()

self.editor1 = QtGui.QTextEdit()
self.editor2 = QtGui.QTextEdit()
self.editor3 = QtGui.QTextEdit()
self.editor4 = QtGui.QTextEdit()

self.split1 = QtGui.QSplitter()
self.split2 = QtGui.QSplitter()
self.split3 = QtGui.QSplitter()
self.split2.setOrientation(QtCore.Qt.Vertical)
self.split3.setOrientation(QtCore.Qt.Vertical)

self.split2.addWidget(self.editor1)
self.split2.addWidget(self.editor2)
self.split3.addWidget(self.editor3)
self.split3.addWidget(self.editor4)

self.connect(self.split2, QtCore.SIGNAL("splitterMoved"), self.split3.moveSplitter)
self.connect(self.split3, QtCore.SIGNAL("splitterMoved"), self.split2.moveSplitter)

self.split1.addWidget(self.split2)
self.split1.addWidget(self.split3)

self.layout = QtGui.QHBoxLayout()
self.layout.addWidget(self.split1)
self.window.setLayout(self.layout)

def main() :
qApp = QtGui.QApplication(sys.argv)
qApp.setStyle('cleanlooks')
aw = ApplicationWindow()
aw.show()
sys.exit(qApp.exec_())

if __name__ == '__main__':
main()

有什么想法吗?

最佳答案

好吧,我终于找到了如何使用 python 做到这一点:

import sys
from PyQt4 import QtGui, QtCore

class ApplicationWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setAttribute(QtCore.Qt.WA_DeleteOnClose)
self.setWindowTitle("Cluster View")
self.initUI()

self.window.setFocus()
self.setCentralWidget(self.window)
self.showMaximized()

def splitterMoved(self, sender) :
print ("ok", sender)
receiver = self.split2 if sender is self.split3 else self.split3
receiver.blockSignals(True)
receiver.setSizes(sender.sizes())
receiver.blockSignals(False)

def initUI(self) :
self.window = QtGui.QWidget()

self.editor1 = QtGui.QTextEdit()
self.editor2 = QtGui.QTextEdit()
self.editor3 = QtGui.QTextEdit()
self.editor4 = QtGui.QTextEdit()

self.split1 = QtGui.QSplitter()
self.split2 = QtGui.QSplitter()
self.split3 = QtGui.QSplitter()
self.split2.setOrientation(QtCore.Qt.Vertical)
self.split3.setOrientation(QtCore.Qt.Vertical)

self.split2.addWidget(self.editor1)
self.split2.addWidget(self.editor2)
self.split3.addWidget(self.editor3)
self.split3.addWidget(self.editor4)

self.connect(self.split2, QtCore.SIGNAL("splitterMoved(int, int)"), lambda x : self.splitterMoved(self.split2))
self.connect(self.split3, QtCore.SIGNAL("splitterMoved(int, int)"), lambda x : self.splitterMoved(self.split3))

self.split1.addWidget(self.split2)
self.split1.addWidget(self.split3)

self.layout = QtGui.QHBoxLayout()
self.layout.addWidget(self.split1)
self.window.setLayout(self.layout)

def main() :
qApp = QtGui.QApplication(sys.argv)
qApp.setStyle('cleanlooks')
aw = ApplicationWindow()
aw.show()
sys.exit(qApp.exec_())

if __name__ == '__main__':
main()

也许有更好的方法可以做到这一点,但至少现在有效。

关于python - PyQt4 : Connect splitter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41810173/

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