get clicked date current ?
-
@Duy-Khang
Depends on what widget class that picture is showing. You say nothing. Are we supposed to guess? -
Hi
You can use this signal
https://doc.qt.io/qt-5/qcalendarwidget.html#activated
or
void QCalendarWidget::clicked(const QDate &date) -
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; });
-
Hi
in .hclass 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.
-
Hi
in .hclass 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.
-
@mrjj can you show me which document to learn about QObject::connect() and be master like you ? hihi
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