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:

Qt Code:
  1. ...
  2. dateEdit->installEventFilter(this);
  3. ....
  4.  
  5.  
  6. bool Ventana::eventFilter(QObject *obj, QEvent *event)
  7.  
  8. {
  9.  
  10. if (event->type() == QEvent::FocusIn)
  11. {
  12. QFocusEvent *event2 ;
  13. event2 = dynamic_cast< QFocusEvent * >( event );
  14. if (event2->reason() != Qt::ActiveWindowFocusReason)
  15. {
  16.  
  17. dateEdit->setCurrentSectionIndex(2);
  18. dateEdit->setSelectedSection(dateEdit->currentSection());
  19. return true;
  20. }
  21. else
  22. {
  23. return QObject::eventFilter(obj, event);
  24. }
  25. }
  26.  
  27. else
  28. {
  29. return QObject::eventFilter(obj, event);
  30. }
  31.  
  32. }
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