Results 1 to 5 of 5

Thread: Highlighting selected section on QDateTimeEdit

  1. #1
    Join Date
    Jan 2006
    Posts
    12
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Highlighting selected section on QDateTimeEdit

    I have subclassed QDateTimeEdit for viewing the current date and time. User has also ability to change the date/time. As my system has no mouse I was wondering how do I set a specific section as selected (highlighted or similar so the user can see which section he is about to change). Key presses are used for selecting the section to be changed on QDateTimeEdit and for changing the current section value.

    The problem is that user cant see which section is selected, at least not until he changes the value and the section where QDateTimeEdit::setCurrentSection() is set to be pointing gets highlighted.
    The logic on changing the date/time is ok now, but I dont know how to set the section selected for user point of view, as in the way it gets higlighted when you change the value by stepUp(), stepDown() or stepBy().

    Surely I could just do

    Qt Code:
    1. stepUp();
    2. stepDown();
    To copy to clipboard, switch view to plain text mode 

    to get the section highlighted, but that would mess up setting the dates when it's 1st or last day of the month and wrapping is set to false. And If i set the wrapping on, it only works when decreasing values (on date field: 2->1->31->30), not when they are increased (on datefield: 30->31->31->31).

    I thought that QDateTimeEdit::setCurrentSection() would do the trick of highlighting the current section, but I was wrong.

    I'm using Qt 4.1 on linux.

  2. #2
    Join Date
    Jan 2006
    Posts
    12
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Highlighting selected section on QDateTimeEdit

    I tried to figure out what happens when you call stepBy() from Qt's source code, but I didn't find what causes the currentSelection field to be highlighted. I think this is something simple I just haven't been able to figure out?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Highlighting selected section on QDateTimeEdit

    Qt Code:
    1. void QAbstractSpinBox::stepUp()
    2. {
    3. stepBy(1);
    4. }
    5.  
    6. void QAbstractSpinBox::stepBy(int steps)
    7. {
    8. // ...
    9. selectAll();
    10. }
    11.  
    12. void QDateTimeEdit::stepBy(int steps)
    13. {
    14. // ...
    15. d->setSelected(d->currentSectionIndex);
    16. }
    17.  
    18. void QDateTimeEditPrivate::setSelected(int sectionIndex, bool forward)
    19. {
    20. if (specialValue()) {
    21. edit->selectAll();
    22. } else {
    23. // ...
    24. if (forward) {
    25. edit->setSelection(sectionPos(node), size);
    26. } else {
    27. edit->setSelection(sectionPos(node) + size, -size);
    28. }
    29. }
    30. }
    To copy to clipboard, switch view to plain text mode 
    Unfortunately setSelected() is in private part of the QDateTimeEdit implementation, so you can't use it directly.

  4. #4
    Join Date
    Jul 2009
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Highlighting selected section on QDateTimeEdit

    I'm sorry to bring that thread up, but I actually have the same problem right now.
    Meanwhile, it seems that a couple of functions were added to Qt, of which setSelectedSection,
    but no matter what I do, the cursor always stays on the first section until the user interacts with the GUI.
    Did anybody get the same behavior here ?

  5. #5
    Join Date
    May 2013
    Posts
    1
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: Highlighting selected section on QDateTimeEdit

    Unless its been fixed in a recent release (probably not but I havent tried - cant afford the disk space for more than 2 parallel versions of qt)...

    Then, what you describe should probably be classified as a long time bug in Qt, that is, an inconsistency between the direct keyboard editing and software only control.

    I usually steer well clear from GUIs and Commodity software...

    Anyway so that you know, none of the previous suggestions will give you the correct behaviour and
    the solution is not going to be as obvious as anyone has previously attempted to point out.
    You are going to have to do what I did and get well acquainted with debugging the Qt Libraries.
    In the end I made a very small fix/workaround in the Qt Libraries to get this to work.

    Since I think Commodity/Free software and lack of regulation hurts the working Software Professional I will not post my version of the fix/workaround in the public domain. I will
    leave that to some other person that believes doing work for free somehow greatly
    improves their fiscal and career prospects in the "commodity software employers" buyers
    market.

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.