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. CalendarWidget sync
QtWS25 Last Chance

CalendarWidget sync

Scheduled Pinned Locked Moved Unsolved General and Desktop
calendar
6 Posts 2 Posters 2.0k 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.
  • C Offline
    C Offline
    cbrwx
    wrote on last edited by
    #1

    Hello!

    First of thanks to anyone who takes the time to help me out here!

    Anyway; my problem is, as i am rather fresh in qt: syncing a calendarwidget(display widget/calendar widget) to a LineEdit, meaning whatever i write in the LineEdit field should update the calendar aswell. I have somewhat solved this the other way around tho using this:

    void Myfancyprogram::on_calendarWidget_selectionChanged()
    {
        ui->txt_dato->setText(ui->calendarWidget->selectedDate().toString("yyyy-MM-dd"));
    }
    

    So if i lets say load a date from a table in a database and fill out the LineEdit, how do i automaticly update the CalendarWidget aswell? And i am not asking for the database code, just if there is a way, like above to simply update the calendarwidget based upon whats in the LineEdit field?

    Much love,,

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

      Hi,

      You can use setSelectedData with a QDate built using the content of your QLineEdit using one of the QDate::fromString overload.

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

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        You can use setSelectedData with a QDate built using the content of your QLineEdit using one of the QDate::fromString overload.

        C Offline
        C Offline
        cbrwx
        wrote on last edited by
        #3

        Alright and thank you for the tip!

        I followed your advice more or less, at least i didn't stray from my skill path :p

        Iv'e been looking at the syntax and so far i have this, please tell me if i am on the right path, and how eventually i could arrive there; if you see it.

        void Myfancyprog::on_txt_dato_textChanged(const QString &arg1)
        {
            QString date_test;
            date_test=ui->txt_dato->text();
            QDateTime date;
            date.fromString(date_test, "yyyy-MM-dd");
         }
        
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          You are missing the call to ui->calendarWidget->setSelectedDate(date);.

          Did you also ensure that you can only enter valid date in your QLineEdit ?

          By the way, why not use a QDateEdit widget ?

          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
            cbrwx
            wrote on last edited by
            #5

            Iv'e actually tried that but it gave me a couple of errors(no matching function call, no known conversion for argument 1), however i am too much a noob to realise i was maybe onto something and moved on. And apparantly still am, any suggestions?

            And i know(believe,fairly certain(maybe)) i'm sending it in the right format, I cannot use dateedit because the data is being stored in a database in a way i cannot modify, which in turn would make it an even bigger endavour than making my problem work this way :p

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

              What exact error did you get ?

              What format is it ? How are you retrieving it ?

              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

              • Login

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