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. QDateTimeEdit clear text

QDateTimeEdit clear text

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 2.6k Views
  • 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.
  • beeckscheB Offline
    beeckscheB Offline
    beecksche
    wrote on last edited by
    #1

    In my application i show some times with the QDateTimeEdit widget on the screen.

    I want to clear the text of the QDateTimeEdit widget with the clear() function of the class.

    When i call the clear() function, only the current section will be cleared, not the whole text/time. So i tried to change the currentSection property, but without success.

    In the Qt Designer i'm not able to change the property, the property always switches back to HourSection.
    Change the currentSection property directly in the constructor also has no effect.

    I use the widget with followed properties:

    frame = false
    readOnly = true
    buttonSymbols = QAbstractSpinBox::NoButtons
    displayFormat = "HH:mm"
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      Do you mean so the area is completely blank
      or that value reset to 00:00 ?

      beeckscheB 1 Reply Last reply
      0
      • mrjjM mrjj

        Hi
        Do you mean so the area is completely blank
        or that value reset to 00:00 ?

        beeckscheB Offline
        beeckscheB Offline
        beecksche
        wrote on last edited by
        #3

        @mrjj
        when i call the clear() function the HourSection is completely blank and the SecondSection is reset to 00.

        For me it would be nice to have the whole area to be completely blanked.

        mrjjM 1 Reply Last reply
        1
        • beeckscheB beecksche

          @mrjj
          when i call the clear() function the HourSection is completely blank and the SecondSection is reset to 00.

          For me it would be nice to have the whole area to be completely blanked.

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

          @beecksche
          Ok, so its sort of both. :)
          Just tried here on Qt 5.6 and nothing happened at all with clear() :?!

          beeckscheB 1 Reply Last reply
          0
          • mrjjM mrjj

            @beecksche
            Ok, so its sort of both. :)
            Just tried here on Qt 5.6 and nothing happened at all with clear() :?!

            beeckscheB Offline
            beeckscheB Offline
            beecksche
            wrote on last edited by beecksche
            #5

            @mrjj
            I tried it also with Qt5.6 MSVC2013:

            #include <QtWidgets/QApplication>
            #include <QHBoxLayout>
            #include <QDateTimeEdit>
            #include <QToolButton>
            
            int main(int argc, char *argv[])
            {
            	QApplication a(argc, argv);
            	
            	QWidget central;
            
            	QDateTimeEdit *edit = new QDateTimeEdit(&central);	
            	edit->setReadOnly(true); 
            	edit->setButtonSymbols(QAbstractSpinBox::NoButtons);
            	edit->setFrame(false);
            	edit->setDisplayFormat("HH:mm");
            
            	QToolButton *btn = new QToolButton(&central);
            	btn->setText("Clear()");
            
            	QHBoxLayout *layout = new QHBoxLayout(&central);
            	layout->addWidget(edit);
            	layout->addWidget(btn);
            	
            	QObject::connect(btn, &QToolButton::clicked, edit, &QDateTimeEdit::clear);
            
            	central.show();
            
            	return a.exec();
            }
            

            When i click the button only the selected section will be cleared/blanked. Once i clicked in the QDateTimeEdit widget the number is shown again. Either i missunderstood the doc or there is a bug in QDateTimeEdit class.

            I changed the way to display that no time is available with specialValueText property. So i do not have to call the clear() function at all. The text will be shown if the current value is equal to the set minimum value:

            #include <QtWidgets/QApplication>
            #include <QHBoxLayout>
            #include <QDateTimeEdit>
            
            int main(int argc, char *argv[])
            {
            	QApplication a(argc, argv);
            	
            	QWidget central;
            
            	QDateTimeEdit *edit = new QDateTimeEdit(&central);	
            	edit->setReadOnly(true); 
            	edit->setButtonSymbols(QAbstractSpinBox::NoButtons);
            	edit->setFrame(false);
            	edit->setDisplayFormat("HH:mm");
            	edit->setSpecialValueText("No time available"); // will be shown when the current time is equal to the minimum
            
            	QHBoxLayout *layout = new QHBoxLayout(&central);
            	layout->addWidget(edit);
            
            	central.show();
            
            	return a.exec();
            }
            
            1 Reply Last reply
            2
            • mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Good workaround.
              Maybe clear was never really implemented in QDateTime as
              it comes from the base class.

              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