[Solved]Activating calender popup on focus in event
-
I have a requirement in which I want to activate the calender popup using the keyboard. But the problem is that, in the focus in event the popup doesn't work.
Please let me know if I need to change the approach or add something more that I am missing.
-
see my DocNote on the "QTimeEdit":http://qt-project.org/doc/qt-4.8/qdatetimeedit.html. You could do something like that in your focus event handler method:
@
void MyDateEdit::focusInEvent ( QFocusEvent * event )
{
QStyleOptionComboBox opt;
this->initStyleOption(&opt);
QRect rect = this->style()->subControlRect(QStyle::CC_ComboBox,&opt,QStyle::SC_ComboBoxArrow);QMouseEvent event(QEvent::MouseButtonPress, rect.center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QApplication::sendEvent(this, &event); QMouseEvent event(QEvent::MouseButtonRelease, rect.center(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier); QApplication::sendEvent(this, &event); QDateEdit::focusInEvent(event);
}
@this should open the calendar popup on focus in.
-
no, because when the calendar popup is enabled the time edit looks more like a combobox than a spinbox right?
And thats even the code QDateTimeEdit uses itself to paint the calendar button internally btw. -
yes you are right.. .sorry.
It over-hasted when i looked it up from some old code of mine. -
@raven-worx I need to do something similar but I do not want to subclass QDateEdit and use focusInEvent(), I use eventFilter in my MainWindow class. Is it possible to use your code?