我想连接分割器以在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()
有什么想法吗?
答案 0 :(得分:1)
好吧我终于找到了如何使用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()
也许有更好的方法可以做到这一点,但至少它现在有效。