简体   繁体   English

从pyqt4的QGridLayout中的仅QLineEdit小部件提取文本

[英]Extracting Text from only QLineEdit widgets in a QGridLayout in pyqt4

I have a QGrid Layout with around 15 widgets consisting of QLabels , QLineEdits and QComboBoxes. 我有一个QGrid布局,包含大约15个由QLabels,QLineEdits和QComboBoxes组成的小部件。 I would like a function which extracts the text from only the QLineEdit widgets. 我想要一个仅从QLineEdit小部件提取文本的函数。

What I mean is something like this 我的意思是这样的

for i in range(self.grid.count()):
    if self.grid.itemAt.widget(i).Type == QtGui.QLineEdit: //Not able to figure out the syntax 
        print self.grid.itemAt.widget(i).text()

Could someone help out with the syntax? 有人可以帮忙语法吗?

You are using the wrong syntax for itemAt . 您为itemAt使用了错误的语法。 Try this: 尝试这个:

    from PyQt4.QtGui import *
    ...
    for i in range(self.grid.count()):
        w = self.grid.itemAt(i).widget()
        print isinstance(w, QLineEdit)

It should work just fine. 它应该工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM