get clicked date current ?
-
Hi
You can use this signal
https://doc.qt.io/qt-5/qcalendarwidget.html#activated
or
void QCalendarWidget::clicked(const QDate &date) -
wrote on 15 May 2021, 07:17 last edited by
can you give me an example ?
-
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; });
-
wrote on 15 May 2021, 09:30 last edited by
and help me show normal slot, i use nomal slot but it doesn't work
-
wrote on 15 May 2021, 09:43 last edited by
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
-
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.
-
wrote on 15 May 2021, 10:20 last edited by
thank you very much.!
-
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 -
wrote on 15 May 2021, 14:02 last edited by
okay, thanks a lot !
12/12