Seite 1 von 1

QDateEdit und QTimeEdit deselektieren

Verfasst: 1. November 2008 10:11
von uwe_kornnagel
Hallo,
ich habe in einer Anwendung mehrere QDateEdits und QTimeEdits. Bei der Clearfunktion sollen alle QDateEdits auf das aktuelle Datum und alle QTimeEdits auf 00:00 gesetzt werden.

Code: Alles auswählen

void TTerminEdit::Clear() {
	{    
		QList <QDateEdit*> objs = findChildren<QDateEdit*>();
		while ( !objs.isEmpty() ) {
			objs.first()->setDate ( QDate::currentDate() );
			objs.pop_front();
		}
	}

	{
		QList <QTimeEdit*> objs = findChildren<QTimeEdit*>();
		while ( !objs.isEmpty() ) {
			objs.first()->setTime ( QTime ( 0, 0, 0, 0 ) );
			objs.pop_front();
		}
	}
}
Es funktionier, aber nach Clear() sind alle QDateEdits und QTimeEdites selectiert. Wie kann man sie einfach deselectieren?

Verfasst: 1. November 2008 11:38
von solarix

Code: Alles auswählen

while ( !objs.isEmpty() ) {
         QDateEdit *nextEdt = objs.takeFirst();
         nextEdt->setDate ( QDate::currentDate() ); 
         nextEdt->setSelectedSection (QDateTimeEdit::NoSection);
} 

Verfasst: 1. November 2008 13:05
von uwe_kornnagel
Danke für den Tipp.
solarix hat geschrieben:

Code: Alles auswählen

 nextEdt->setSelectedSection (QDateTimeEdit::NoSection);
in der Doku steht:
Selects section. If section doesn't exist in the currently displayed sections this function does nothing. If section is NoSection this function will unselect all text in the editor. Otherwise this function will move the cursor and the current section to the selected section.
Aber es klappt bei mir nicht, der gesamte Text im Editor bleibt selektiert.