Python Forum

Full Version: return/capture the selected date from QDateEdit's calendar?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like to create a pop up calendar and then select a date to print out the selected Date. So far,I only able to create it using QDateEdit but fail to return the selected date.

below are popupCalendar but not able to select and return the date into label.
def setupUi(self):
        self.calendar1=QDateEdit(self)
        self.calendar1.setCalendarPopup(True)
        self.calendar1.dateChanged.connect(self.show_date)
        selectedDate=self.calendar1.dateChanged 
        print(selectedDate) # check signal
        self.Date_label = QLabel(self)
        self.Date_label.move(50,320)
        self.Date_label.setText(selectedDate.toString())
                    
    def show_date(self, selectedDate):
        self.Date_label.setText(selectedDate.toString())
fail to execute self.Date_label.setText(selectedDate.toString) ,how to return the selected date? Sad Sad
You are right in not showing hundreds lines of code. But now it is a bit difficult, this is apparently a part of a class. And also we don't know what has been imported.
But I see you do
self.Date_label.setText(selectedDate.toString())
... to assign a value. And under show_date you are doing the same. My guess is that in show_date() you need to do:
self.Date_label.Text()
... and you will need to assign or return the result of that method.
(Jul-03-2020, 09:36 AM)ibreeden Wrote: [ -> ]You are right in not showing hundreds lines of code. But now it is a bit difficult, this is apparently a part of a class. And also we don't know what has been imported.
But I see you do
self.Date_label.setText(selectedDate.toString())
... to assign a value. And under show_date you are doing the same. My guess is that in show_date() you need to do:
self.Date_label.Text()
... and you will need to assign or return the result of that method.

thanks for the suggestion ,I figure out the solution :
        date2= selectedDate.toString()
        self.Date_label.setText(date2)
hope others can benefit from sample above .