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. 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?
Forum Updated to NodeBB v4.3 + New Features

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?

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 182 Views 1 Watching
  • 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.
  • Dummie1138D Offline
    Dummie1138D Offline
    Dummie1138
    wrote on last edited by
    #1

    Hi. I have the following code related to some QSpinboxes which are to be updated every second.

    f9270f16-98ae-4eec-b802-8ef156f778d0-image.png

    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 if that 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 valueChanged or editingFinished for connecting to a slot but not something that returns a bool. Please let me know if more info is required.

    JonBJ 1 Reply Last reply
    0
    • Dummie1138D Dummie1138

      Hi. I have the following code related to some QSpinboxes which are to be updated every second.

      f9270f16-98ae-4eec-b802-8ef156f778d0-image.png

      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 if that 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 valueChanged or editingFinished for connecting to a slot but not something that returns a bool. Please let me know if more info is required.

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by JonB
      #2

      @Dummie1138
      What does "being edited" mean for a QSpinBox? The only thing you can check for is whether it has focus. There is no editingFinished signal.

      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 a QElapsedTimer or re-read the wall clock time and subtract the start time periodically.

      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