[Qt-interest] how to change cursor position in an QDateEdit after mouse click on it?

Enrique Cuesta enriquecues at gmail.com
Thu Jul 9 23:09:10 CEST 2009


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);
....


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);
     }

}

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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090709/07a307d4/attachment.html 


More information about the Qt-interest-old mailing list