K
K
Kupyc2011-11-17 13:31:03
PyQt
Kupyc, 2011-11-17 13:31:03

PyQt&PySide: null value in QDateTimeEdit?

My regards.
In Qt (and therefore in the PyQt & PySide bindings) there is such a good thing as QtGui.QDateTimeEdit, which allows you to enter a date and select it using a drop-down calendar. The widget is powerful, but not without a flaw: there is no way to handle null values. Thus, the widget cannot be used in forms where the date is an optional field - it is necessary either to recognize a certain non-zero date (for example, 01/01/1999 00:00) as the date when entering which the field is considered null, or not to use this widget.
There are two solutions: to hack the widget, using some loopholes like setting the text field value directly, bypassing the validators, or writing your own widget, repeating the functionality of the existing one with an accuracy acceptable in the project.
The following methods did not help with the hack:

  • widget.lineEdit().setText("")
  • widget.setSpecialValueText("optional field")
  • widget.clear()

In the version with inheritance from QComboBox, it’s not clear to me personally how to screw the calendar into a drop-down popup where various views like trees, etc. are perfectly screwed.
Inheriting from QLineEdit is hindered by the realization that you have to implement the widget from scratch in general, which means not only formatting and validation, but also care about the coordinated work of the input and calendar widgets: resizing, positioning, showing / hiding the calendar, etc.
Question: how did the community solve this problem?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
proDOOMman, 2011-11-17
@Kupyc

Faced the same problem. As a result, I had to write my own widget, consisting of QLineEdit and QToolButton. The button has a QMenu call with a QWidgetAction in which the QCalendarWidget lives.
On cpp all this took 50 lines of code

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question