gpt4 book ai didi

python - 当从组合框发出信号时将布局插入 QDialog

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

我在 qtdesigner 中创建了一个 ui,如下所示:

enter image description here

我想在标题为“Equation”的组框和包含两个标题为“Subscripts”和“Connected Elements”的组框的布局之间插入另一个包含几个小部件的布局。

我不确定如何插入这个附加布局的原因是,当我查看 qtdesigner 中的对象检查器时,我看到了这个:

enter image description here

它没有告诉我包含对话框窗口中所有其他小部件和布局的垂直布局的名称。

我按如下方式加载用户界面:

from PyQt4.QtGui import *
from PyQt4.QtCore import *
from PyQt4 import uic

class EquationEditor(QDialog):

def __init__(self, parent=None):
super().__init__(parent)

uic.loadUi('equation_editor.ui', self)

# Insert a layout containing a couple of widgets on index change of
# the combobox
self.typeBox.currentIndexChanged.connect(self.enableInitialValueEntry)

def enableInitialValueEntry(self):
vartype = self.typeBox.currentText()

if vartype == "Stock":
hbox = QHBoxLayout()
hbox.addStretch(1)

hbox.addWidget(QLabel("Initial Value"))
hbox.addWidget(QLineEdit())

#How can I insert the layout `hbox`?

最佳答案

包含所有其他布局的布局将是对话框的布局,因此您可以尝试如下操作:

    def enableInitialValueEntry(self):
...
if vartype == "Stock":
...
main_layout = self.layout()
main_layout.insertLayout(2, hbox)

关于python - 当从组合框发出信号时将布局插入 QDialog,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38317141/

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