Hi !
(sorry for my poor english)
I'm new to QT and c++ (just 2 days!)... but I love it !
this is my question:
I have a QDateEdit in my dialog...
with this format: dd/MM/yyyy
I want that when my QDateEdit get the focus (tab, mouse click, etc), select the third section (yyyy)...
QDateEdit has not a slot for focus issues... so... I tried this:
...
dateEdit->installEventFilter(this);
....
{
if (event
->type
() == QEvent::FocusIn) {
if (event2->reason() != Qt::ActiveWindowFocusReason)
{
dateEdit->setCurrentSectionIndex(2);
dateEdit->setSelectedSection(dateEdit->currentSection());
return true;
}
else
{
return QObject::eventFilter(obj, event
);
}
}
else
{
return QObject::eventFilter(obj, event
);
}
}
...
dateEdit->installEventFilter(this);
....
bool Ventana::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::FocusIn)
{
QFocusEvent *event2 ;
event2 = dynamic_cast< QFocusEvent * >( event );
if (event2->reason() != Qt::ActiveWindowFocusReason)
{
dateEdit->setCurrentSectionIndex(2);
dateEdit->setSelectedSection(dateEdit->currentSection());
return true;
}
else
{
return QObject::eventFilter(obj, event);
}
}
else
{
return QObject::eventFilter(obj, event);
}
}
To copy to clipboard, switch view to plain text mode
and this works perfectly always... but when the focus is given by a mouse click...
In that case no section is selected... just the cursor is positioned in the place the mouse clicks (as usual)...
I think that after a mouse click another event or slot or something else is executing after the focusIn event... losing my selected section...
But I don't know how to solve this....
any idea?
Thank you very much
Bookmarks