Results 1 to 4 of 4

Thread: QDateTimeEdit : Dumb Mistake or bug?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,626
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default QDateTimeEdit : Dumb Mistake or bug?

    This code:
    Qt Code:
    1. #include <QApplication>
    2. #include <QDateTimeEdit>
    3.  
    4. int main(int argc, char **argv)
    5. {
    6. QApplication app(argc, argv);
    7.  
    8. edit.setDateTime(QDateTime::currentDateTimeUtc());
    9. edit.setDisplayFormat("yyyy-MM-dd hh:mm");
    10. edit.setSelectedSection(QDateTimeEdit::DaySection);
    11. // also tried these:
    12. // edit.setCurrentSection(QDateTimeEdit::DaySection);
    13. // edit.setCurrentSectionIndex(2);
    14. edit.show();
    15.  
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 
    I would have expected to show the current time with the "dd" day field already selected. What I get with 4.8.5/5.1.0 on 64-bit Linux, and 4.8.4 on 32-bit Windows is the year (first, presumably default) section selected. I have also tried deferring the setSelectedSection() call until after the show() with a zero timer. Meanwhile the currentSection() property returns 0x100, i.e. the DaySection.

    Am I missing the absolutely obvious?
    Last edited by ChrisW67; 11th November 2013 at 08:04.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,545 Times in 1,495 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QDateTimeEdit : Dumb Mistake or bug?

    Looks like a bug to me.

    I tried not setting the datetime format and then it looked like it worked correctly (because my locale format has day as the first section), but then I change the code to select year (third section) and it didn't work either.

    Cheers,
    _

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,391
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: QDateTimeEdit : Dumb Mistake or bug?

    Same here (64 bit linux, Qt 5.1.1).
    Looks like some events are clearing the initial selection to default, because this works ok after the edit widget is shown:
    Qt Code:
    1. #ifndef WIDGET_H
    2. #define WIDGET_H
    3.  
    4. #include <QWidget>
    5. #include <QDateTimeEdit>
    6. #include <QPushButton>
    7.  
    8. class Widget : public QWidget{
    9. Q_OBJECT
    10. public:
    11. Widget(QWidget * parent = NULL)
    12. :QWidget(parent)
    13. {
    14. _btn = new QPushButton("next section",this);
    15. connect(_btn, SIGNAL(clicked()), this, SLOT(nextSection()));
    16. _edit.show();
    17. _edit.setDateTime(QDateTime::currentDateTimeUtc());
    18. _edit.setDisplayFormat("yyyy-MM-dd hh:mm");
    19. }
    20. public slots:
    21. void nextSection(){
    22. static int s = 0;
    23. s = (s+1)%3;
    24. _edit.setCurrentSectionIndex(s);
    25. _edit.setSelectedSection(_edit.currentSection());
    26. }
    27. private:
    28. QPushButton * _btn;
    29. };
    30.  
    31. #endif
    To copy to clipboard, switch view to plain text mode 
    When pressing the button, section is changed as expected.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,626
    Thanks
    13
    Thanked 1,592 Times in 1,520 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QDateTimeEdit : Dumb Mistake or bug?

    I refined it and lodged a bug
    https://bugreports.qt-project.org/browse/QTBUG-34759

    It appears that the focusInEvent() is resetting the currentSection() so I am working around this by subclassing QDateTimeEdit, which is OK for my purposes:
    Qt Code:
    1. class Edit: public QDateTimeEdit {
    2. public:
    3. Edit(QWidget *p): QDateTimeEdit(p) { }
    4. protected:
    5. void focusInEvent(QFocusEvent *event) {
    6. Section section = currentSection();
    7. QDateTimeEdit::focusInEvent(event);
    8. setSelectedSection(section);
    9. }
    10. };
    To copy to clipboard, switch view to plain text mode 

  5. The following user says thank you to ChrisW67 for this useful post:

    LynneV (27th November 2014)

Similar Threads

  1. Dumb newbie SQLITE, C++, Qt question...
    By scott_hollen in forum Newbie
    Replies: 3
    Last Post: 27th January 2011, 12:08
  2. Whre is the mistake?
    By unix7777 in forum Newbie
    Replies: 6
    Last Post: 18th March 2010, 22:30
  3. QComboBox Assert Mistake
    By jfe in forum Qt Programming
    Replies: 8
    Last Post: 30th July 2007, 13:00
  4. Qt Quarterly mistake
    By munna in forum General Discussion
    Replies: 2
    Last Post: 20th June 2006, 19:08
  5. Bug in Qt or Qt Designer or my mistake?
    By [maTa] in forum Qt Programming
    Replies: 5
    Last Post: 9th February 2006, 00:02

Tags for this Thread

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.