2011-12-14 78 views
2

定義済みのリストからボタンを選択するのではなく、テキスト入力をサポートするQt4(実際にはPyQt4)にメッセージボックスを表示する簡単でクリーンな方法はありますか?私は(そして部分的に)このようなダイアログを表示するためのカスタムクラスを作成することでこれを行うことができますが、よりクリーンな方法ではありませんか?Qtメッセージ入力ボックスにテキスト入力

編集:Luca Carlonのおかげです。他の誰かがこれを必要とする場合に備えて、私はここでPyQt4コードを投稿します。

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

答えて

5

QInputDialogを使用してください。静的メソッドgetTextで十分です。

関連する問題