Qt Python Calendar:选定日期直接访问

发布于 2024-08-17 12:11:36 字数 869 浏览 7 评论 0原文

我的日历运行良好。

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

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,然后使用“日期”来获取精确的日期。日等等——效果很好。

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

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

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

高度赞赏所有意见和建议。

I have calendar that is working fine.

Here is the function that display the full date:

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

And here the code with the calendar:

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)

To have direct access to selected day, I am calling the function selectDate based on connect event, and then using the 'date' to obtain the precise date.day and so on -- which is working fine.

The only awkward thing that is annoying me is that it gives the following warning..

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

Any suggestion to stop this TypeError warning?

All comments and suggestions are highly appreciated.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清欢 2024-08-24 12:11:36

我猜想 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

I guess that the slot called by the selectdate signal shouldn't have any argument. You can access the selectedDate by the corresponding calendar method.

See the c++ docs: http://doc.trolltech.com/4.3/widgets-calendarwidget.html

So your code should be something like:

def selectDate(self):
    date = self.calendar.selectedDate()
    self.fullDate = str(date.day()) + " / " + str(date.month()) + " / " + str(date.year())
    print "full date: %s" % self.fullDate
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文