【问题标题】:Qt Python Calendar: selected day direct accessQt Python 日历:选定日期直接访问
【发布时间】:2011-01-01 13:44:39
【问题描述】:

我的日历工作正常。

这是显示完整日期的函数:

def selectDate(self,date):
    self.fullDate = str(date.day()) + " / " + str(date.month()) + " / " + str(date.year())
    print "full date: %s" % self.fullDate

这里是带有日历的代码:

def TabCalendar(self):
    self.calendar = QtGui.QCalendarWidget(self.tab)
    self.calendar.setGeometry(QtCore.QRect(self.x1, self.y1, self.x2, self.y2)) 

    QtCore.QObject.connect(self.calendar, QtCore.SIGNAL("selectionChanged()"), self.selectDate)
    QtCore.QObject.connect(self.calendar, QtCore.SIGNAL("clicked(QDate)"), self.selectDate)

为了直接访问选定的日期,我根据连接事件调用函数 selectDate,然后使用“日期”来获取精确的 date.day 等等——效果很好。

唯一让我恼火的是它给出了以下警告..

TypeError: turbSchedule_selectDate() takes exactly 2 arguments (1 given)

有什么建议可以停止这个 TypeError 警告吗?

非常感谢所有 cmets 和建议。

【问题讨论】:

    标签: python qt date calendar typeerror


    【解决方案1】:

    我猜 selectdate 信号调用的槽不应该有任何参数。您可以通过相应的日历方法访问 selectedDate。

    请参阅 c++ 文档:http://doc.trolltech.com/4.3/widgets-calendarwidget.html

    所以你的代码应该是这样的:

    def selectDate(self):
        date = self.calendar.selectedDate()
        self.fullDate = str(date.day()) + " / " + str(date.month()) + " / " + str(date.year())
        print "full date: %s" % self.fullDate
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-05-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-29
      • 1970-01-01
      相关资源
      最近更新 更多