[英]How to display QLineEdit on the window?
I created a small window using PyQt4 and Pydev. 我使用PyQt4和Pydev创建了一个小窗口。 The code is below:
代码如下:
import sys
from PyQt4 import QtGui
from PyQt4 import QtCore
# Create GUI object
app = QtGui.QApplication(sys.argv)
widget = QtGui.QWidget()
widget.setGeometry(400,300,800,800) # Position window
widget.resize(450,250) # Resize window
widget.setWindowTitle('Sample') # Set Title of the window
Password = QtGui.QLineEdit() # Input Box for password
widget.show() # Display window
# Exit program
sys.exit(app.exec_())
I created the Password LineEdit box but how to show on the active window, which is represented by widget ? 我创建了密码LineEdit框,但是如何在小部件代表的活动窗口中显示呢?
Just use 只需使用
Password = QtGui.QLineEdit(widget)
This tells Qt that you want widget
to be the parent of the QLineEdit
. 这告诉Qt您希望
widget
成为QLineEdit
的父级。 If you leave out the widget
, then the QLineEdit
has no parent, so it's not shown. 如果您忽略
widget
,则QLineEdit
没有父级,因此不会显示。
Update: To position child items in parent windows, you'll have to read up about layouts (I assume you want to do it properly, not as a toy/learning exercise). 更新:要在父窗口中放置子项,您必须阅读有关布局的信息(我想您想正确地进行布局,而不是作为玩具/学习练习)。 Any good PyQt book should be able to help, eg this one .
任何一本好的PyQt书籍都应该能够提供帮助,例如这一本书。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.