Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QDateTimeEdit with date *and* time picker
QtWS25 Last Chance

QDateTimeEdit with date *and* time picker

Scheduled Pinned Locked Moved Unsolved General and Desktop
qdatetimeeditdate pickertime picker
6 Posts 3 Posters 17.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Stefan Scherfke
    wrote on 27 Sept 2016, 12:50 last edited by
    #1

    Hi,

    I want to create a DateTimeEdit with a popup that contains both, a date picker and a time picker (as shown in the image below or in this live example).
    alt text

    I have read the docs of QDateTimeEdit and QCalendarWidget and also read parts of QDateTimeEdit's source code, but I am still not sure what would be the best approach to implement this (in PyQt5, but I guess whether I do it in Python or C++ is not too important for the general approach).

    The internal QCalendarPopup class already seems to have a layout component that could, in theory, contain a calendar widget as well as a "TimeSelectionWidget". However, I have no idea how to extend it in a clean way.

    Cheers,
    Stefan

    R 1 Reply Last reply 27 Sept 2016, 13:08
    0
    • S Stefan Scherfke
      27 Sept 2016, 12:50

      Hi,

      I want to create a DateTimeEdit with a popup that contains both, a date picker and a time picker (as shown in the image below or in this live example).
      alt text

      I have read the docs of QDateTimeEdit and QCalendarWidget and also read parts of QDateTimeEdit's source code, but I am still not sure what would be the best approach to implement this (in PyQt5, but I guess whether I do it in Python or C++ is not too important for the general approach).

      The internal QCalendarPopup class already seems to have a layout component that could, in theory, contain a calendar widget as well as a "TimeSelectionWidget". However, I have no idea how to extend it in a clean way.

      Cheers,
      Stefan

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 27 Sept 2016, 13:08 last edited by
      #2

      @Stefan-Scherfke
      i haven't tried it but it should be possible:

      QDateTimeEdit* dt = new QDateTimeEdit;
      QWidget* popup = dt->calendarWidget()->window();
      QListView* timeList = new QListView;
      //init timeList widget
      
      QWidget* container = new QWidget;
      // set the layout and add the "calendar widget" and "timeList" widgets (and buttosn) to your needs
      
      QVBoxLayout *popupLayout = qobject_cast<QVBoxLayout*>(popup->layout());
      QLayoutItem *item;
       while( (item = popupLayout ->takeAt(0)) )
               delete item;
      popupLayout->addWidget( container );
      

      Also you need to make sure to select the time (in the time list view) whenever the datetime changes.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      S 1 Reply Last reply 27 Sept 2016, 13:42
      5
      • R raven-worx
        27 Sept 2016, 13:08

        @Stefan-Scherfke
        i haven't tried it but it should be possible:

        QDateTimeEdit* dt = new QDateTimeEdit;
        QWidget* popup = dt->calendarWidget()->window();
        QListView* timeList = new QListView;
        //init timeList widget
        
        QWidget* container = new QWidget;
        // set the layout and add the "calendar widget" and "timeList" widgets (and buttosn) to your needs
        
        QVBoxLayout *popupLayout = qobject_cast<QVBoxLayout*>(popup->layout());
        QLayoutItem *item;
         while( (item = popupLayout ->takeAt(0)) )
                 delete item;
        popupLayout->addWidget( container );
        

        Also you need to make sure to select the time (in the time list view) whenever the datetime changes.

        S Offline
        S Offline
        Stefan Scherfke
        wrote on 27 Sept 2016, 13:42 last edited by
        #3

        @raven-worx Thank you very much!

        I already got a minimal example working. I'll post a complete example once everything works well. :)

        1 Reply Last reply
        3
        • S Offline
          S Offline
          Stefan Scherfke
          wrote on 12 Oct 2016, 12:44 last edited by
          #4

          I made some progress and the new widgets looks quite good (not perfect, though):
          datetimepopup.png.

          The problem with resizing and spacing everything correclty is, that I can't access all of the calendar widget's privates stuff.

          This also leads to problems with signals/slots. By default, the calendar popup sets the DateTimeEdit's date and closes, if I click on the month calendar. However, I only want to to set the Date/Time and close the Window when I click on the Done button, so that I can select a Date, an Hour and Minute. Therefore, I need to disconnect the original signals, but they are not accessible, too.

          I don't really want to write my own CalendarWidget-clone just to do these minor modifications. What else could I do?

          R 1 Reply Last reply 12 Oct 2016, 12:51
          0
          • M Offline
            M Offline
            mrjj
            Lifetime Qt Champion
            wrote on 12 Oct 2016, 12:50 last edited by
            #5

            Hi
            Did you try implementing mousePress and not call base class?
            You can maybe eat the mouse event that triggers the signal to be sent and
            that way remove the popup.

            1 Reply Last reply
            0
            • S Stefan Scherfke
              12 Oct 2016, 12:44

              I made some progress and the new widgets looks quite good (not perfect, though):
              datetimepopup.png.

              The problem with resizing and spacing everything correclty is, that I can't access all of the calendar widget's privates stuff.

              This also leads to problems with signals/slots. By default, the calendar popup sets the DateTimeEdit's date and closes, if I click on the month calendar. However, I only want to to set the Date/Time and close the Window when I click on the Done button, so that I can select a Date, an Hour and Minute. Therefore, I need to disconnect the original signals, but they are not accessible, too.

              I don't really want to write my own CalendarWidget-clone just to do these minor modifications. What else could I do?

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 12 Oct 2016, 12:51 last edited by
              #6

              @Stefan-Scherfke said in QDateTimeEdit with date *and* time picker:

              What else could I do?

              Possibilities:

              1. install an event Filter on the popup widget (window) and intercept the CloseEvent and call ignore() on it and return true in the event-filter
              2. call blockSignals(true) on all widgets which shouldn't trigger signals

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved