PDA

View Full Version : QDateEdit read-only with calendar not r.o.



lauranger
24th January 2007, 16:01
Hi
When dateEditInstance->setReadOnly(true) is executed,
the dateEdit can not be changed by entering digits. This is ok.
But as the calendar was showable, it is still shown if user clicks
on the button. Can still be ok, but user should not be able
to change the date, in any way. Right ? As of 4.2.2, the user can
do it by the way of the calendar.
Anyone have noticed this behaviour ?
I've seen no bugs filed for this at the moment on trolltech task tracker.
Anyone can think of a lightest workaround ?
I'd say forbid calendar popup when set read-only false.
Thanks in advance.

Laurent G.

jpn
24th January 2007, 16:46
To be able to show a read only calendar popup seems to require an ugly hack, but here it is..


class ReadOnlyDateEdit : public QDateEdit
{
public:
ReadOnlyDateEdit(QWidget* parent = 0)
: QDateEdit(parent), disconnected(false)
{
}

protected:
void mousePressEvent(QMouseEvent* event)
{
QDateEdit::mousePressEvent(event);
if (!disconnected && calendarPopup())
{
QWidget* popup = findChild<QWidget*>("qt_datetimedit_calendar");
if (popup)
{
qDebug() << disconnect(popup, SIGNAL(newDateSelected(QDate)), this, SLOT(setDate(QDate)));
qDebug() << disconnect(popup, SIGNAL(hidingCalendar(QDate)), this, SLOT(setDate(QDate)));
qDebug() << disconnect(popup, SIGNAL(activated(QDate)), this, SLOT(setDate(QDate)));
}
}
}

private:
bool disconnected;
};

lauranger
24th January 2007, 17:14
ugly is really necessary to your sentence ;)
Thank you Jpn.