【发布时间】:2022-01-15 16:51:47
【问题描述】:
将 QtDesigner 和 PyQt5 与 pyuic5 一起使用,我正在设置具有可变行数的 FormLayout。 每行都是在 QtDesigner 中创建的自定义小部件,由 QLabel 和包含 QLineEdit 和 QPushButton 的 QHBoxLayout 组成。
我使用
创建行用户界面 def get_data_widget(parent=None, **kwargs):
widget = QtWidgets.QWidget(parent)
dlg_ui = wgtDataRow.Ui_Form() # from the custom made widget
dlg_ui.setupUi(widget)
# recursively ensure all objectName()s are unique
rename_widget(widget, "_%s" % unique_id())
dlg_ui.label.setText(kwargs.get('name') or '')
dlg_ui.editData.setText(kwargs.get('value') or '')
return dlg_ui
在 QDialog 方法中将行 UI 插入到 QFormLayout 中:
def add_data_entry_row(self, name, **kwargs):
# simplified code, but this is the bit that affects the QFormLayout
posn = kwargs.get('position', 0)
data_ui = get_data_widget(self, name=name, value=kwargs.get('value'))
self.dlg_ui.formLayout.insertRow(posn, data_ui.label, data_ui.widget)
我遇到的问题是 QFormLayout 的第一行没有响应鼠标点击。
如果我在 0 处插入新行,则先前无响应的行将向下移动并变为响应,而新的(顶部)行无响应。
任何人都可以对此有所了解吗?
【问题讨论】:
-
好吧,越来越好奇了。如果我展开包含对话框,在短暂的时间间隔后,顶行 QPushButton 会响应鼠标单击,但 QLineEdit 仍然没有响应
-
墨菲再次出击!我花了一些时间设置了一个最小的示例,尽管 pyuic5 生成的代码并不是那么简单,当然,一切都很完美。
标签: pyqt5 qt5 qt-designer