带文本输入的Qt显示消息框

问题描述:

是否有任何简单而干净的方式在Qt4(实际上是PyQt4)中显示一个支持文本输入的消息框,而不仅仅是从预定义列表中选择一个按钮?我可以(也可以部分)通过编写一个自定义类来完成这个任务,只是为了显示这样的对话框,但是没有更清晰的方法吗?带文本输入的Qt显示消息框

编辑:我得到它的工作感谢卢卡卡隆。但是以防万一别人需要这个,我会后在这里工作如下

from PyQt4.QtGui import QInputDialog 
#This code works only inside a method of a widget or window as self must refer to a 
#valid widget or window to get the correct modality, although we can give None instead 
(text,truth)=QInputDialog.getText(self,"Get text","User name",QLineEdit.Normal,"NoName") 
if truth: 
    #The user has accepted the edit, he/she has clicked OK 
    print text 
else: 
    #The user has not accepted the edit, he/she has clicked Cancel 
    print "No change" 
+0

感谢您的编辑,为我节省了更多的时间 – James 2016-08-16 17:41:50

使用QInputDialog PyQt4的代码这一点。静态方法getText可能已经足够。