Results 1 to 2 of 2

Thread: how to change cursor position in an QDateEdit after mouse click on it?

  1. #1
    Join Date
    Jul 2009
    Posts
    74
    Thanks
    2
    Thanked 6 Times in 6 Posts

    Default how to change cursor position in an QDateEdit after mouse click on it?

    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

  2. #2
    Join Date
    May 2009
    Posts
    62
    Thanks
    2
    Thanked 16 Times in 15 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to change cursor position in an QDateEdit after mouse click on it?

    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?
    This is probably the MouseButtonPress event that arrives after the FocusIn event. You could try to suppress it in your event filter, but then you couldn't position the text cursor any more by clicking.

Similar Threads

  1. Ignore mouse click on window activation
    By shentian in forum Qt Programming
    Replies: 2
    Last Post: 22nd June 2009, 19:08
  2. Word at mouse click position in QGraphicsTextItem
    By pherthyl in forum Qt Programming
    Replies: 2
    Last Post: 3rd November 2008, 05:56
  3. Replies: 11
    Last Post: 15th July 2008, 14:11
  4. QGraphicItem mouse click detection
    By PrimeCP in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2007, 12:35
  5. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 10:05

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.