这可能是一个非常愚蠢的问题,但无论如何我对它感到震惊: - (
我有一个带有两个并排列表的窗口和一个带有标签的行编辑控件(参见附图)。我想要的是将行编辑字段放在相应标签之后而不是第二列表之下。
这是我的测试代码:
import sys
from PyQt4 import Qt, QtCore, QtGui
class MainWindow(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
centralLayout = QtGui.QGridLayout()
centralLayout.setSpacing(2)
treelist1 = QtGui.QTreeWidget()
treelist2 = QtGui.QTreeWidget()
treelist1.setColumnCount(1)
treelist1.setHeaderLabels(["List 1"])
treelist2.setColumnCount(1)
treelist2.setHeaderLabels(["List 2"])
label = QtGui.QLabel("Line:")
linedit = QtGui.QLineEdit()
centralLayout.setRowStretch(0, 8)
centralLayout.setRowStretch(1, 1)
centralLayout.addWidget(treelist1, 0, 0)
centralLayout.addWidget(treelist2, 0, 1)
centralLayout.addWidget(label, 1, 0)
centralLayout.addWidget(linedit, 1, 1)
self.setLayout(centralLayout)
self.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
sys.exit(app.exec_())
提前感谢您提供的任何帮助!
答案 0 :(得分:2)
您需要的是:
答案 1 :(得分:2)
根据ypnos的建议,这是我的问题的答案:
import sys
from PyQt4 import Qt, QtCore, QtGui
class MainWindow(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
verticalLayout = QtGui.QVBoxLayout()
verticalLayout.setSpacing(2)
horizontalLayout1 = QtGui.QHBoxLayout()
horizontalLayout2 = QtGui.QHBoxLayout()
treelist1 = QtGui.QTreeWidget()
treelist2 = QtGui.QTreeWidget()
treelist1.setColumnCount(1)
treelist1.setHeaderLabels(["List 1"])
treelist2.setColumnCount(1)
treelist2.setHeaderLabels(["List 2"])
label = QtGui.QLabel("Line:")
linedit = QtGui.QLineEdit()
horizontalLayout1.addWidget(treelist1)
horizontalLayout1.addWidget(treelist2)
horizontalLayout2.addWidget(label)
horizontalLayout2.addWidget(linedit)
verticalLayout.addLayout(horizontalLayout1)
verticalLayout.addLayout(horizontalLayout2)
self.setLayout(verticalLayout)
self.show()
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
mw = MainWindow()
sys.exit(app.exec_())