Hw来实现具有多行和多列的QFormLayout

问题描述 投票:0回答:2

我如何实现具有多个行和列的from?我目前正在使用QFormLayout,其中每一行都是一个QLabel和QLineEdit,如[]中所示

#!/usr/bin/python3

from PyQt5.QtWidgets import (QApplication, QWidget, QFormLayout, QLabel,
        QLineEdit)

import sys

app = QApplication([])
win = QWidget()
layout = QFormLayout()
layout.addRow('Name:', QLineEdit())
layout.addRow('Phone:', QLineEdit())
win.setLayout(layout)
win.setGeometry(50,50,400,200)
win.show()
app.exec_()

渲染

enter image description here

因此,如果我想使用包含多行和多列的表单,我是否必须执行类似的操作

#!/usr/bin/python3

from PyQt5.QtWidgets import (QApplication, QWidget, QFormLayout, QLabel,
        QLineEdit, QGridLayout)

import sys

app = QApplication([])
win = QWidget()
layout = QGridLayout()
nameLabel = QLabel('Name:');    layout.addWidget(nameLabel, 0, 0)
nameInput = QLineEdit();        layout.addWidget(nameInput, 0, 1)
phoneLabel = QLabel('Phone:');  layout.addWidget(phoneLabel, 1, 0)
phoneInput = QLineEdit();       layout.addWidget(phoneInput, 1, 1)
addrLabel = QLabel('Address:'); layout.addWidget(addrLabel, 0, 2)
addrInput = QLineEdit();        layout.addWidget(addrInput, 0, 3)
zipLabel = QLabel('Zip:');      layout.addWidget(zipLabel, 1, 2)
zipInput = QLineEdit();         layout.addWidget(zipInput, 1, 3)
win.setLayout(layout)
win.setGeometry(50,50,400,200)
win.show()
app.exec_()

呈现

enter image description here

这是唯一的方法...这是不可扩展的。

请原谅术语屠宰...我可以使用QGrid类型的对象来包含两个水平对齐的QForm对象吗?我认为这意味着

  • 创建QHBoxLayout
  • 向此布局添加QGrid
  • Grid.cell(0,0)将是QForm_a
  • Grid.cell(0,1)将是QForm_b

我如何实现具有多个行和列的from?我目前正在使用QFormLayout,其中每一行都是一个QLabel和QLineEdit,如PyQt5.QtWidgets import(...)#usr / bin / python3中的(...

python pyqt pyqt5
2个回答
0
投票

您可以尝试使用Qtable小部件:


0
投票

感谢您的反馈,我以这种方式解决了我的问题。

© www.soinside.com 2019 - 2024. All rights reserved.