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.
  • Stefan ScherfkeS Offline
    Stefan ScherfkeS Offline
    Stefan Scherfke
    wrote on 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

    raven-worxR 1 Reply Last reply
    0
    • Stefan ScherfkeS Stefan Scherfke

      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

      raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on 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

      Stefan ScherfkeS 1 Reply Last reply
      5
      • raven-worxR raven-worx

        @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.

        Stefan ScherfkeS Offline
        Stefan ScherfkeS Offline
        Stefan Scherfke
        wrote on 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
        • Stefan ScherfkeS Offline
          Stefan ScherfkeS Offline
          Stefan Scherfke
          wrote on 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?

          raven-worxR 1 Reply Last reply
          0
          • mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on 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
            • Stefan ScherfkeS Stefan Scherfke

              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?

              raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on 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