我有一个QVBoxLayout,我已经添加了一些小部件,通过addWidget().我现在需要删除那些小部件,似乎我需要使用removeWidget()(它需要删除一个小部件)来做到这一点.
我认为调用children()或findChildren(QWidget)在我的布局上会返回我添加到其中的小部件列表; 不过,我在调试器中,并且只是接收空列表.
我非常误解了什么吗?我上周刚刚开始做PyQT,并且主要是通过API文档的试错来学习.
我用Qt Designer创建了一个GUI并通过它访问它
def loadUiWidget(uifilename, parent=None):
loader = QtUiTools.QUiLoader()
uifile = QtCore.QFile(uifilename)
uifile.open(QtCore.QFile.ReadOnly)
ui = loader.load(uifile, parent)
uifile.close()
return ui
MainWindow = loadUiWidget("form.ui")
MainWindow.show()
children = MainWindow.children()
button1 = MainWindow.QPushButton1
Run Code Online (Sandbox Code Playgroud)
"children"已经包含在UI中创建的小部件"QPushButton1","QTextBrowser1",但是不应该通过recoursive findChildren()方法访问它们?
访问.ui文件小部件的优雅方法是什么?
参考: 找到正确的实例, Load .ui文件
与我们在 PyQt Layout 中 Loop over widgets 的问题类似,但有点复杂...
我有
QVGridLayout
QGroupBox
QGridLayout
QLineEdit
Run Code Online (Sandbox Code Playgroud)
我想访问 QLineEdit 但到目前为止我不知道如何访问 QGroupBox 的孩子
for i in range(self.GridLayout.count()):
item = self.GridLayout.itemAt(i)
for i in range(item.count()):
lay = item.itemAt(i)
edit = lay.findChildren(QLineEdit)
print edit.text()
Run Code Online (Sandbox Code Playgroud)
any1可以指出我正确的方向吗?