wxpython设计GUI:选中wxFormBuilder工具wxCalendarCtrl控件,实现自动选择日期功能
wxPython设计界面转PyQt5设计界面,相同的界面功能,通过移植wxPython源代码实现PyQt5相同界面功能,在实现上述链接提到的自动选择日期区间功能时,发现相同逻辑代码实现的事件触发在wxPython中可行,在PyQt5中不可行,wxPython中日期控件是通过鼠标双击事件触发的,而在PyQt5中日期控件是通过日期值改变作为事件触发的。这个问题有待解决。
# 日期选择功能
# 设置日期格式为 "yyyy-MM-dd",只显示日期
self.order_dateEdit.setDisplayFormat("yyyy-MM-dd")
# 设置为当前日期
self.order_dateEdit.setDate(QDate.currentDate())
self.order_dateEdit.dateChanged.connect(self.choice_last_date)
def choice_last_date(self, date):
last_date = date.toString("yyyy/MM/dd")
self.order_check_lineEdit.setText(last_date)
self.last_date = last_date
self.order_dateEdit.dateChanged.connect(self.choice_next_date)
def choice_next_date(self, date):
next_date = date.toString("yyyy/MM/dd"))
if self.last_date.strip() != "":
next_date = self.last_date + "_" + next_date
self.order_check_lineEdit.setText(next_date)
self.order_dateEdit.dateChanged.connect(self.choice_last_date)
wxPython中日期控件的关键代码
self.last_date = ""
self.m_calendar1.Bind(wx.adv.EVT_CALENDAR, self.choice_last_date)
def choice_last_date(self, event):
last_date = event.GetDate()
value = str(last_date).split(" ")[0]
self.m_textCtrl25.SetValue(value)
self.last_date = value
self.m_calendar1.Bind(wx.adv.EVT_CALENDAR, self.choice_next_date)
def choice_next_date(self, event):
next_date = event.GetDate()
value = str(next_date).split(" ")[0]
if self.last_date.strip() != "":
value = self.last_date + "_" + value
self.m_textCtrl25.SetValue(value)
self.m_calendar1.Bind(wx.adv.EVT_CALENDAR, self.choice_last_date)