下面的腳本是創建包含QDateTimeEdit和QPushButton只有一個非常簡單的GUI的.clear()方法(該腳本可以運行):正確使用上QDateTimeEdit
import sys
import os
from PyQt4 import QtGui
from PyQt4 import *
class SmallGUI(QtGui.QMainWindow):
def __init__(self):
super(SmallGUI,self).__init__()
self.initUI()
def initUI(self):
self.setGeometry(300,300,300,300)
self.setWindowTitle('Sample')
#Calendar input
self.MyInput = QtGui.QDateTimeEdit(self)
self.MyInput.setCalendarPopup(True)
self.MyInput.setDisplayFormat("dd/MM/yyyy hh:mm")
self.MyInput.setGeometry(88,25,110,20)
###############
#Clear button
self.MyButton = QtGui.QPushButton(self)
self.MyButton.setGeometry(QtCore.QRect(88,65,110,20))
self.MyButton.setText('Clear date')
###############
QtCore.QObject.connect(self.MyButton,QtCore.SIGNAL("clicked(bool)"),self.clearDate)
self.show()
def clearDate(self):
self.MyInput.clear()
def main():
app = QtGui.QApplication(sys.argv)
sampleForm = SmallGUI()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
當我點擊「清除日期「按鈕,但是,QDateTimeEdit的.clear()方法僅清除前兩個值(僅當天),並且它似乎停在」/「處。我試圖閱讀一些對象的文檔,但我找不到自己的方式。有沒有人知道如何在按下按鈕時完全清空輸入框?
我對代碼的格式非常抱歉,但我發誓,我不能做什麼了,我看到正確的縮進到編輯器,但不進顯示的問題;出於某種原因,我無法訪問StackOverflow編輯器的任何功能來編寫問題,我將不得不在Meta Stack Overflow上打開一個線程。 –