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. get clicked date current ?
Forum Updated to NodeBB v4.3 + New Features

get clicked date current ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
12 Posts 3 Posters 751 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.
  • D Duy Khang

    gg.png

    how can i get date when a cell date clicked ?

    JonBJ Offline
    JonBJ Offline
    JonB
    wrote on last edited by
    #2

    @Duy-Khang
    Depends on what widget class that picture is showing. You say nothing. Are we supposed to guess?

    1 Reply Last reply
    1
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi
      You can use this signal
      https://doc.qt.io/qt-5/qcalendarwidget.html#activated
      or
      void QCalendarWidget::clicked(const QDate &date)

      1 Reply Last reply
      3
      • D Offline
        D Offline
        Duy Khang
        wrote on last edited by
        #4

        can you give me an example ?

        mrjjM 1 Reply Last reply
        0
        • D Duy Khang

          can you give me an example ?

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @Duy-Khang

          Hi
          Its just a connect. Here i used a lambda but you can ofc also connect to a normal slot.

            connect(ui->calendarWidget, &QCalendarWidget::clicked, this, [](const QDate & date) {
                  qDebug() << "Data is" << date;
              });
          
          1 Reply Last reply
          1
          • D Offline
            D Offline
            Duy Khang
            wrote on last edited by
            #6

            and help me show normal slot, i use nomal slot but it doesn't work

            1 Reply Last reply
            0
            • D Offline
              D Offline
              Duy Khang
              wrote on last edited by
              #7

              QObject::connect(calendar,SIGNAL(selectionChanged()),this,SLOT(onSelectionChanged()));

              void Student_Interactive_Interface::onSelectionChanged()
              {
              qDebug()<<calendar->selectedDate().toString("dd/MM/yyyy");
              }

              but,it doesn't work

              1 Reply Last reply
              0
              • mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #8

                Hi
                in .h

                class MainWindow : public QMainWindow
                {
                    Q_OBJECT
                ...    
                public slots:
                    void DateSelected(const QDate & date);
                
                

                or

                public slots:
                    void selectionChanged();
                

                and in .cpp

                void MainWindow::DateSelected(const QDate &date)
                {
                    qDebug() << "Date is" << date;
                }
                or
                void MainWindow::selectionChanged()
                {
                    qDebug()<<ui->calendarWidget->selectedDate().toString("dd/MM/yyyy");
                }
                
                

                connect(ui->calendarWidget, &QCalendarWidget::clicked, this, &MainWindow::DateSelected );
                or
                connect(ui->calendarWidget, &QCalendarWidget::selectionChanged, this, &MainWindow::selectionChanged );

                both work so make sure that calendar is infact the one you have on the screen and not another one.

                D 1 Reply Last reply
                1
                • D Offline
                  D Offline
                  Duy Khang
                  wrote on last edited by
                  #9

                  thank you very much.!

                  1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Hi
                    in .h

                    class MainWindow : public QMainWindow
                    {
                        Q_OBJECT
                    ...    
                    public slots:
                        void DateSelected(const QDate & date);
                    
                    

                    or

                    public slots:
                        void selectionChanged();
                    

                    and in .cpp

                    void MainWindow::DateSelected(const QDate &date)
                    {
                        qDebug() << "Date is" << date;
                    }
                    or
                    void MainWindow::selectionChanged()
                    {
                        qDebug()<<ui->calendarWidget->selectedDate().toString("dd/MM/yyyy");
                    }
                    
                    

                    connect(ui->calendarWidget, &QCalendarWidget::clicked, this, &MainWindow::DateSelected );
                    or
                    connect(ui->calendarWidget, &QCalendarWidget::selectionChanged, this, &MainWindow::selectionChanged );

                    both work so make sure that calendar is infact the one you have on the screen and not another one.

                    D Offline
                    D Offline
                    Duy Khang
                    wrote on last edited by
                    #10

                    @mrjj can you show me which document to learn about QObject::connect() and be master like you ? hihi

                    mrjjM 1 Reply Last reply
                    0
                    • D Duy Khang

                      @mrjj can you show me which document to learn about QObject::connect() and be master like you ? hihi

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @Duy-Khang

                      Hi
                      As you noticed, there are 2 versions. the old one using the SIGNAL and SLOT words, and the new one I did use here.

                      The new one is better than the old one as it will give a compiler error if something does not match. like missing parameters etc.

                      https://wiki.qt.io/New_Signal_Slot_Syntax

                      how it works, is explained here
                      https://doc.qt.io/qt-5/signalsandslots.html

                      1 Reply Last reply
                      2
                      • D Offline
                        D Offline
                        Duy Khang
                        wrote on last edited by
                        #12

                        okay, thanks a lot !

                        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