QtGui.QLineEdit is a widget that allows to enter and edit a single line of plain text. There are undo and redo, cut and paste, and drag & drop functions available for the widget.

#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial This example shows text which
is entered in a QtGui.QLineEdit
in a QtGui.QLabel widget. author: Jan Bodnar
website: zetcode.com
last edited: August 2011
""" import sys
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.lbl = QtGui.QLabel(self)
qle = QtGui.QLineEdit(self) qle.move(60, 100)
self.lbl.move(60, 40) qle.textChanged[str].connect(self.onChanged) self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('QtGui.QLineEdit')
self.show() def onChanged(self, text): self.lbl.setText(text)
self.lbl.adjustSize() def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()

This example shows a line edit widget and a label. The text that we key in the line edit is displayed immediately in the label widget.

qle = QtGui.QLineEdit(self)

The QtGui.QLineEdit widget is created.

qle.textChanged[str].connect(self.onChanged)

If the text in the line edit widget changes, we call the onChanged() method.

def onChanged(self, text):

    self.lbl.setText(text)
self.lbl.adjustSize()

Inside the onChanged() method, we set the typed text to the label widget. We call the adjustSize()method to adjust the size of the label to the length of the text.

Figure: QtGui.QLineEdit

QtGui.QLineEdit的更多相关文章

  1. QLineEdit 自动完成(使用setCompleter,内含一个ListView)

    -------------------------------------CompleteLineEdit.h------------------------------------- #ifndef ...

  2. pyqt pyside QLineEdit 重写键盘事件

    pyqt pyside QLineEdit 重写键盘事件 def keyPressEvent(self, event): if (event.modifiers() & QtCore.Qt.S ...

  3. QtGui.QInputDialog

    The QtGui.QInputDialog provides a simple convenience dialog to get a single value from the user. The ...

  4. PyQt4入门学习笔记(五)

    PyQt4里的对话框 对话框是大多数GUI应用中不可分割的一部分.一个对话框是两者或多者的会话.在GUI内,对话框是应用向人说话的方式.一个对话框可以用来输入数据,修改数据,改变应用设置等等. QtG ...

  5. PyQt4入门学习笔记(三)

    # PyQt4入门学习笔记(三) PyQt4内的布局 布局方式是我们控制我们的GUI页面内各个控件的排放位置的.我们可以通过两种基本方式来控制: 1.绝对位置 2.layout类 绝对位置 这种方式要 ...

  6. Pyqt+QRcode 生成 识别 二维码

    1.生成二维码 python生成二维码是件很简单的事,使用第三方库Python QRCode就可生成二维码,我用Pyqt给QRcode打个壳 一.python-qrcode介绍 python-qrco ...

  7. linux下使用多线程编写的聊天室

    自从开始学linux网络编程后就想写个聊天室,一开始原本打算用多进程的方式来写,可是发觉进程间的通信有点麻烦,而且开销也大,后来想用多线程能不能实现呢,于是便去看了一下linux里线程的用法,实际上只 ...

  8. python GUI输入窗口

    为了解决 sublime text 下 python 的 raw_input() 函数无法起效,便萌生了个用 GUI 窗口来获取输入的想法,一开始想用 Tkinter,后来想了下还是用 PyQt 吧, ...

  9. Pyqt 一个简单的浏览器

    使用QtWebKit 做一个简单的浏览器. mybrowserUI.ui <?xml version="1.0" encoding="UTF-8"?> ...

随机推荐

  1. [UOJ30]/[CF487E]Tourists

    [UOJ30]/[CF487E]Tourists 题目大意: 一个\(n(n\le10^5)\)个点\(m(m\le10^5)\)条边的无向图,每个点有点权.\(q(q\le10^5)\)次操作,操作 ...

  2. Codeforces Beta Round #10 D. LCIS 动态规划

    D. LCIS 题目连接: http://www.codeforces.com/contest/10/problem/D Description This problem differs from o ...

  3. BZOJ 4027: [HEOI2015]兔子与樱花 树上dp

    4027: [HEOI2015]兔子与樱花 Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline ...

  4. mysql max_allowed_packet 设置

    mysql根据my.cnf中max_allowed_packet的大小来限制接收到的数据包大小. 据官网描述,如下图. 数据包的值范围为1k~1G, 只能是1024的倍数,不能整除1024的,会向下取 ...

  5. vultr购买主机前的测速地址

    https://www.vultr.com/faq/ 拉倒最下面,有个地区测速,每个点开之后ping,看延迟再进行购买,因为对应不同的宽带速度不一样. 参考: https://pdf-lib.org/ ...

  6. IDA设置函数类型

    http://www.2cto.com/shouce/ida/1361.htm Action name: SetType 该命令允许你指定当前条目类型. 如果光标处在函数内部,那么函数类型将会被编辑, ...

  7. Spring EL bean引用实例

    在Spring EL,可以使用点(.)符号嵌套属性参考一个bean.例如,“bean.property_name”. public class Customer { @Value("#{ad ...

  8. innodb_buffer_pool_size=30G

    Starting program: /usr/local/mysql-5.6.27-linux-glibc2.5-x86_64/bin/mysqld-debug --user=mysql --data ...

  9. Windows上安装Git替代cmd命令行程序

    git是一个版本管理系统,利用好它,可以管理你项目文件,每个文件的更新删除修改,它都知道,还可以还原回历史的某个版本. msysgit是Windows版的Git. 1.下载地址:https://git ...

  10. Mysql 会导致锁表的语法

    最近再找一些Mysql锁表原因,整理出来一部分sql语句会锁表的,方便查阅,整理的不是很全,都是工作中碰到的,会持续更新 笔者能力有限,如果有不正确的,或者不到位的地方,还请大家指出来,方便你我,方便 ...