Reputation: 117
How to modify local date in PyQt application (i needed to change it on linux and win platform)? E.g.:
>>> date_now = QtCore.QDate.currentDate()
>>> print date_now
>>> PyQt4.QtCore.QDate(2014, 3, 3)
...some code for change current date
>>> date_now = QtCore.QDate.currentDate()
>>> print date_now
>>> PyQt4.QtCore.QDate(2012, 1, 1)
Notice: external system date must not change.
Upvotes: 0
Views: 188
Reputation: 32429
You can monkey-patch QDate
:
QtCore.QDate.currentDate = lambda: QtCore.QDate(2012, 1, 1)
Which might lead to inconsistencies somewhere else.
Working example:
Python 3.3.2+ (default, Oct 9 2013, 14:50:09)
[GCC 4.8.1] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from PyQt4 import QtCore
>>> QtCore.QDate.currentDate()
PyQt4.QtCore.QDate(2014, 3, 3)
>>> QtCore.QDate.currentDate = lambda: QtCore.QDate(2012, 1, 1)
>>> QtCore.QDate.currentDate()
PyQt4.QtCore.QDate(2012, 1, 1)
>>>
For python2.7:
class PatchedQDate (QtCore.QDate):
@classmethod
def currentDate (cls):
return QtCore.QDate (2012, 1, 1)
QtCore.QDate = PatchedQDate
Upvotes: 2