PDA

View Full Version : QDateEdit with QCalendarWidget always shown



JoZCaVaLLo
30th March 2011, 17:09
Hallo!!!

Already Googled around but no solution found... How should I modify my QDateEdit so that as soon as I get in, the QCalendarWidget gets shown???

I tried the following, but it doesn't work...


void MyDateEdit::focusInEvent(QFocusEvent * e)
{
QDateTimeEdit::focusInEvent(e);
calendarWidget()->show();
}

Rhayader
30th March 2011, 17:25
If you need a QCalenderWidget all the time then you can use it directly without the QDateEdit. It is even available in designer.

JoZCaVaLLo
31st March 2011, 13:01
That's not what i need.

I'm inside a QTableView... or even a form. I wish that the user can both write directly into the QDateEdit or click on the QCalendarWidget. But instead of having to click on the button to show the QCalendarWidget, I'd like the QCalendarWidget to be shown as soon as the QDateEdit gets focused.

wysota
31st March 2011, 14:35
There is no easy way to do what you want. Showing the calendar is easy but it's likely it will pop up in a wrong place:

QWidget *popup = findChild<QWidget*>("qt_datetimedit_calendar");
if(popup)
popup->show();
else
qWarning() << "Popup not initialized";
so you'll have to calculate the position yourself the same way QDateTimeEdit does.

You can force the widget to popup the calendar by sending it a key event with Qt::Key_NumberSign or Qt::Key_Select keys.