PyQt标准框——QInputDialog(二)
生活随笔
收集整理的這篇文章主要介紹了
PyQt标准框——QInputDialog(二)
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
如何通過自定義方式來實現標準輸入框呢?
總體思路就是先生成一個QInputDialog的實例,然后開始設置具體屬性就好了。
1.int類型的Dialog如何生成。
#coding=utf-8 import sys from PyQt4.QtGui import * from PyQt4.QtCore import *app = QApplication(sys.argv) dialog = QInputDialog() #生成一個自定義的QInputDialog的實例 dialog.setInputMode(1) #自定義輸入框的模式 dialog.setIntMinimum(2) #自定義最小值 dialog.setIntMaximum(9) #自定義最大值 dialog.setIntStep(2) #自定義步長 dialog.setIntValue(5) #自定義輸入框顯示的值 dialog.setLabelText("Please Input a int") #自定義提示標簽 dialog.setWindowTitle("Input dialog of int") #自定義窗口標題 print dialog.intMaximum() dialog.setOkButtonText(u"確定") #自定義按鈕的文本值 dialog.setCancelButtonText(u"取消") if dialog.exec_():print dialog.intValue() app.exec_()- 相關函數
- int intMaximum (self)? 返回所設最大值
- int intMinimum (self)?? 返回所設最小值
- int intStep (self)?????????? 返回步長
- int intValue (self)
- setIntMaximum (self, int?max)
- setIntMinimum (self, int?min)
- setIntRange (self, int?min, int?max)
- setIntStep (self, int?step)
- setIntValue (self, int?value)
2.double類型的輸入框
#coding=utf-8
app = QApplication(sys.argv) dialog = QInputDialog() #生成一個自定義的QInputDialog的實例 dialog.setInputMode(2) #自定義輸入框的模式 dialog.setDoubleMinimum(2) #自定義最小值 dialog.setDoubleMaximum(9) #自定義最大值 dialog.setDoubleDecimals(3) #自定義步長 dialog.setDoubleValue(5) #自定義輸入框顯示的值 dialog.setLabelText("Please Input a double") #自定義提示標簽 dialog.setWindowTitle("Input dialog of double") #自定義窗口標題 print dialog.doubleMaximum() dialog.setOkButtonText(u"double-確定") #自定義按鈕的文本值 dialog.setCancelButtonText(u"double-取消") if dialog.exec_():print dialog.doubleValue() app.exec_()double類型的輸入框不能設置步長
相關函數:
- setDoubleDecimals (self, int?decimals)
- setDoubleMaximum (self, float?max)
- setDoubleMinimum (self, float?min)
- setDoubleRange (self, float?min, float?max)
- setDoubleValue (self, float?value)
- int doubleDecimals (self)
- float doubleMaximum (self)
- float doubleMinimum (self)
- float doubleValue (self)
3.text類型的輸入框
#coding=utf-8
import sys from PyQt4.QtGui import * from PyQt4.QtCore import *app = QApplication(sys.argv) dialog = QInputDialog() #生成一個自定義的QInputDialog的實例 dialog.setInputMode(0) #自定義輸入框的模式 dialog.setTextEchoMode(QLineEdit.Password) #自定義輸入框的模式 dialog.setTextValue("this is a customed method") #自定義輸入框的內容 dialog.setLabelText("Please Input a text") #自定義提示標簽 dialog.setWindowTitle("Input dialog of text") #自定義窗口標題 dialog.setOkButtonText(u"text-確定") #自定義按鈕的文本值 dialog.setCancelButtonText(u"text-取消") if dialog.exec_():print dialog.textValue() app.exec_()相關函數:
- setTextEchoMode (self, QLineEdit.EchoMode?mode)
- setTextValue (self, QString?text)
- QLineEdit.EchoMode textEchoMode (self)
- QString textValue (self)
4.Item類型的輸入框
#coding=utf-8
import sys from PyQt4.QtGui import * from PyQt4.QtCore import *app = QApplication(sys.argv) dialog = QInputDialog() #生成一個自定義的QInputDialog的實例 dialog.setInputMode(0) #自定義輸入框的模式 list=QStringList() list.append(u"男") list.append(u"女") dialog.setComboBoxItems(list) #添加列表,形成列表 dialog.setComboBoxEditable(False) #設置不能進行手動編輯 dialog.setLabelText("Please Input a ComboBox") #自定義提示標簽 dialog.setWindowTitle("Input dialog of ComboBox") #自定義窗口標題 dialog.setOkButtonText(u"ComboBox-確定") #自定義按鈕的文本值 dialog.setCancelButtonText(u"ComboBox-取消") if dialog.exec_():print dialog.textValue() app.exec_()好像不能設置current值
相關函數:
- setComboBoxEditable (self, bool?editable)
- setComboBoxItems (self, QStringList?items)
5.設置共同屬性函數: - setLabelText (self, QString?text)
- setOkButtonText (self, QString?text)
- setCancelButtonText (self, QString?text)
總結
以上是生活随笔為你收集整理的PyQt标准框——QInputDialog(二)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 如何使用cd命令
- 下一篇: show()和exec()的区别