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. Set current date in QCalendarWidget
Forum Updated to NodeBB v4.3 + New Features

Set current date in QCalendarWidget

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 4.3k Views 1 Watching
  • 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.
  • C Offline
    C Offline
    Chrisw01
    wrote on last edited by
    #1

    Hi, hello.

    I am using a QCalendarWidget for date input that is stored in a QLineEdit. When I double click the QLineEdit box it pops up a QCalendarWidget for date selection. I wish to set the current date that is already displayed in the QLineEdit. I have found this in the Docs.

    selectedDate : QDate
    
    This property holds the currently selected date.
    
    The selected date must be within the date range specified by the minimumDate and maximumDate properties. By default, the selected date is the current date.
    
    Access functions:
    
    QDate  selectedDate() const
    void setSelectedDate(const QDate &date)
    
    

    However, setSelectedDate does not appear to be a valid function of QCalendarWidget.

    What am I missing here?

    Thanks

    Chris...

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Fuel
      wrote on last edited by Fuel
      #2

      You need to pass a QDate to that Method. In your QLineEdit which format has your Date? Maybe you need to set QDate with QDate::fromString(string, format) an pass it to QCalendarWidget

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Chrisw01
        wrote on last edited by
        #3

        Not sure I follow you, can you provide example?

        Thhanks

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Out of curiosity, why note use a QDateEdit ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Chrisw01
            wrote on last edited by
            #5

            Hi,

            Original design was user inputted a date in form of dd/mm/yyyy, then later on I changed it to a popup style calendar. Which works great, I just want to have the calendar start off on the date that's in the box instead of current date.

            Thanks

            1 Reply Last reply
            0
            • F Offline
              F Offline
              Fuel
              wrote on last edited by
              #6

              Then pass the Date in the QLineEdit to the QCalendarWidget wit setSelectedDate() or show the Error you get.

              1 Reply Last reply
              1
              • C Offline
                C Offline
                Chrisw01
                wrote on last edited by
                #7

                Hi Guys, and thanks for the help.

                The issue was setCurrentDate() was not a valid function. The problem was, I set my QCalendarWidget class as private within the popup class. Once I wrote a function within the popup class to modify the current date all works as expected.

                Thanks. again.

                1 Reply Last reply
                0

                • Login

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