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. Codeforces 1129 D. Isolation

    Codeforces 1129 D. Isolation 解题思路: 令 \(f(l,r)\) 为 \([l,r]\) 中之出现一次的元素个数,然后可以得到暴力 \(\text{dp}\) 的式子. ...

  2. UOJ #30. [CF Round #278] Tourists

    UOJ #30. [CF Round #278] Tourists 题目大意 : 有一张 \(n\) 个点, \(m\) 条边的无向图,每一个点有一个点权 \(a_i\) ,你需要支持两种操作,第一种 ...

  3. [NOI2015]寿司晚宴 --- 状压DP

    [NOI2015]寿司晚宴 题目描述 为了庆祝NOI的成功开幕,主办方为大家准备了一场寿司晚宴. 小G和小W作为参加NOI的选手,也被邀请参加了寿司晚宴. 在晚宴上,主办方为大家提供了n−1种不同的寿 ...

  4. [BZOJ5093]图的价值(NTT+第二类Stirling数)

    5093: [Lydsy1711月赛]图的价值 Time Limit: 30 Sec  Memory Limit: 256 MBSubmit: 250  Solved: 130[Submit][Sta ...

  5. 【贪心】BZOJ3668-[NOI2014]起床困难综合症

    [题目大意] 给定n次操作(与,或,异或),在0~m中选择一个数,使这个数经过n次操作后得到的值最大. [思路] 水题orz 枚举这个数每一位的取值是0还是1,然后根据它经过n次操作后的结果判断: ( ...

  6. BSGS 模板

    模板如下: 扩展版本: 求解a^k=b %p 求k,最小的k一定小于p,否则会重复,否则无解 *********************** gcd(a,p)=1时 设k=mi+v m=sqrt(p) ...

  7. serial-input, parallel-output (SIPO) chip : TPIC6595 , 74HC164 , 74HC4094 or 74HC595

    http://electronics.stackexchange.com/questions/6676/which-sipo-chip-is-better-74hc4094-or-74hc595-or ...

  8. 3DShader之法线贴图(normal mapping)

    凹凸贴图(bump mapping)实现的技术有几种,normal mapping属于其中的一种,这里实现在物体的坐标系空间中实现的,国际惯例,上图先: 好了讲下原理 可以根据高度图生成法线量图,生成 ...

  9. windows下gVim(Vi/vim)基本使用

    Vim 是一个Linux 平台上功能非常强大的编辑器,他是早年的Vi 编辑器的加强版.这个gVim 是windows 版的,并且有了标准的windows 风格的图形界面,所以叫g(graphical) ...

  10. iOS设计模式:静态工厂相关

    工厂方法模式 定义创建对象的接口,让子类决定实例化哪一个类,工厂方法使得一个类的实例化延迟到其子类. *最初的定义出现于<设计模式>(Addison-Wesley,1994) 注意:我讲解 ...