如何从 QLineEdit 动态获取文本? [英] How to get text from a QLineEdit dynamically?

查看:38
本文介绍了如何从 QLineEdit 动态获取文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从 QlineEdit 获取 String(Text)?
我试过这样.myArea.getList() 函数是获取字符串值并用字符串值检查数据库并返回列表

How could get String(Text) from QlineEdit?
I tried Like this. myArea.getList() function is get string value and check database with string value and return List

self.a = QLineEdit()
self.b = QlineEdit()
....

self.b = self.myArea.getList(str(self.a.textChanged.connect(self.textchanged)))

def textchanged(self, text):
    self.my_edit = text

a中输入文本,然后a发生变化.读取a,通过a检查数据,创建b的数据,在b中输入文本,读取b,通过b

Input text in a, then a changes. read a, check data by a, b's data created, Input text in b, read b, check data by b

首先,我不知道如何获取QLineEdit() 的值.打印 QLineEdit 文本有效但返回字符串.

First, I don't know how to get QLineEdit()'s value. print QLineEdit Text works but return String.

推荐答案

这里有一个完整的例子,如何从 self.aself.b 和将值设置为彼此.也许这个教程也能帮到你.

Here is a complete example how to get the value from self.a and self.b and set the values to each other. Maybe this tutorial helps you, too.

不能使用self.textchangedAself.textchangedB方法的返回值,所以必须使用类的成员变量.

You can not use the return value of the methods self.textchangedA or self.textchangedB, so you have to make use of the member variables of the class.

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
import sys
from PyQt4 import QtGui

log = logging.getLogger(__name__)


class MyWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        super(MyWidget, self).__init__(parent)

        vbox = QtGui.QVBoxLayout(self)
        self.setLayout(vbox)

        self.a = QtGui.QLineEdit(self)
        self.b = QtGui.QLineEdit(self)

        vbox.addWidget(self.a)
        vbox.addWidget(self.b)

        self.a.textChanged.connect(self.textchangedA)
        self.b.textChanged.connect(self.textchangedB)

    def textchangedA(self, text):
        log.info("Text from a: %s", text)
        log.info("Text from b: %s", self.b.text())
        # do the processing

    def textchangedB(self, text):
        log.info("Text from b: %s", text)
        log.info("Text from a: %s", self.a.text())



def test():
    app = QtGui.QApplication(sys.argv)
    w = MyWidget()
    w.show()
    sys.exit(app.exec_())

if __name__ == '__main__':
    logging.basicConfig(level=logging.DEBUG)
    test()

这篇关于如何从 QLineEdit 动态获取文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆