Is there a function that returns a bool to check whether a QSpinbox is being edited? If not, what would be needed to build one?
-
Hi. I have the following code related to some QSpinboxes which are to be updated every second.

SetDateTime::SetDateTime(QWidget *parent) : QDialog(parent), ui(new Ui::SetDateTime) { setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); ui->setupUi(this); this->move(0, 0); setter.setDate(QDate(2000, 1, 1)); //setter is QDateTime setter; setter.setTime(QTime(0, 0, 0)); Controller::get()->requestTime(); clock = new QTimer(this); connect(clock, SIGNAL(timeout()), this, SLOT(ticker())); clock->start(1000); } void SetDateTime::ticker(){ setter = setter.addSecs(1); qDebug() << "setter time: " << setter; //I want to stop things from being modified if the brackets are still being set ui->spinBox_date->setValue(setter.date().day()); ui->comboBox_Month->setCurrentIndex(setter.date().month() - 1); ui->spinBox_Year->setValue(setter.date().year()); ui->spinBox_Hour->setValue(setter.time().hour()); ui->spinBox_Min->setValue(setter.time().minute()); if (setter.time().hour() < 10){ ui->spinBox_Hour->setPrefix("0"); } else{ ui->spinBox_Hour->setPrefix(""); } if (setter.time().minute() < 10){ ui->spinBox_Min->setPrefix("0"); } else{ ui->spinBox_Min->setPrefix(""); } }I want the ticker to not modify the QSpinboxes if any of them are being edited and in my mind the best way would be to set up an
ifthat checks if the QSpinboxes are being edited. So far the way I thought about implementing it is:bool minEditing; //A bool to be defined in the h file of the class. void SetDateTime::on_spinBox_Min_valueChanged(int arg1){ minEditing = true; } void SetDateTime::on_spinBox_Min_editingFinished(){ minEditing = false; } void SetDateTime::ticker(){ setter = setter.addSecs(1); qDebug() << "setter time: " << setter; //I want to stop things from being modified if the brackets are still being set if(!minEditing){ ui->spinBox_date->setValue(setter.date().day()); ui->comboBox_Month->setCurrentIndex(setter.date().month() - 1); ui->spinBox_Year->setValue(setter.date().year()); ui->spinBox_Hour->setValue(setter.time().hour()); ui->spinBox_Min->setValue(setter.time().minute()); } if (setter.time().hour() < 10){ ui->spinBox_Hour->setPrefix("0"); } else{ ui->spinBox_Hour->setPrefix(""); } if (setter.time().minute() < 10){ ui->spinBox_Min->setPrefix("0"); } else{ ui->spinBox_Min->setPrefix(""); } }But, I am wondering whether there are any inbuilt functions for such an effect. So far I have found that there are signals like
valueChangedoreditingFinishedfor connecting to a slot but not something that returns a bool. Please let me know if more info is required. -
Hi. I have the following code related to some QSpinboxes which are to be updated every second.

SetDateTime::SetDateTime(QWidget *parent) : QDialog(parent), ui(new Ui::SetDateTime) { setWindowFlags(Qt::FramelessWindowHint| Qt::WindowSystemMenuHint); ui->setupUi(this); this->move(0, 0); setter.setDate(QDate(2000, 1, 1)); //setter is QDateTime setter; setter.setTime(QTime(0, 0, 0)); Controller::get()->requestTime(); clock = new QTimer(this); connect(clock, SIGNAL(timeout()), this, SLOT(ticker())); clock->start(1000); } void SetDateTime::ticker(){ setter = setter.addSecs(1); qDebug() << "setter time: " << setter; //I want to stop things from being modified if the brackets are still being set ui->spinBox_date->setValue(setter.date().day()); ui->comboBox_Month->setCurrentIndex(setter.date().month() - 1); ui->spinBox_Year->setValue(setter.date().year()); ui->spinBox_Hour->setValue(setter.time().hour()); ui->spinBox_Min->setValue(setter.time().minute()); if (setter.time().hour() < 10){ ui->spinBox_Hour->setPrefix("0"); } else{ ui->spinBox_Hour->setPrefix(""); } if (setter.time().minute() < 10){ ui->spinBox_Min->setPrefix("0"); } else{ ui->spinBox_Min->setPrefix(""); } }I want the ticker to not modify the QSpinboxes if any of them are being edited and in my mind the best way would be to set up an
ifthat checks if the QSpinboxes are being edited. So far the way I thought about implementing it is:bool minEditing; //A bool to be defined in the h file of the class. void SetDateTime::on_spinBox_Min_valueChanged(int arg1){ minEditing = true; } void SetDateTime::on_spinBox_Min_editingFinished(){ minEditing = false; } void SetDateTime::ticker(){ setter = setter.addSecs(1); qDebug() << "setter time: " << setter; //I want to stop things from being modified if the brackets are still being set if(!minEditing){ ui->spinBox_date->setValue(setter.date().day()); ui->comboBox_Month->setCurrentIndex(setter.date().month() - 1); ui->spinBox_Year->setValue(setter.date().year()); ui->spinBox_Hour->setValue(setter.time().hour()); ui->spinBox_Min->setValue(setter.time().minute()); } if (setter.time().hour() < 10){ ui->spinBox_Hour->setPrefix("0"); } else{ ui->spinBox_Hour->setPrefix(""); } if (setter.time().minute() < 10){ ui->spinBox_Min->setPrefix("0"); } else{ ui->spinBox_Min->setPrefix(""); } }But, I am wondering whether there are any inbuilt functions for such an effect. So far I have found that there are signals like
valueChangedoreditingFinishedfor connecting to a slot but not something that returns a bool. Please let me know if more info is required.@Dummie1138
What does "being edited" mean for aQSpinBox? The only thing you can check for is whether it has focus. There is noeditingFinishedsignal.Separately: you have a timer expiring every second and code in
ticker()which adds 1 second for the time to show. How accurate do you expect this to be? The timeout may occur any time after 1 second has elapsed. You should not rely on it expiring at exactly one second. This may mean your time "wanders" over a period. Suggest you use aQElapsedTimeror re-read the wall clock time and subtract the start time periodically.