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. Disregard Checkbox changes when Cancel is clicked.

Disregard Checkbox changes when Cancel is clicked.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 1.4k 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.
  • HashTagJFH Offline
    HashTagJFH Offline
    HashTagJF
    wrote on last edited by kshegunov
    #1

    Can someone help me with this? I want to disregard the changes in the checkbox when cancel button is clicked. I used the following codes but it didn't work.

    void MainWindow::on_Cancel_clicked()
    {
    
    if (ui->checkBox->isChecked()){
     ui->checkBox->setChecked(false);
    }
    
    else{
     ui->checkBox->setChecked(true);
    }
    }
    

    [Moved to General and Desktop ~kshegunov]

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What exactly doesn't work ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • HashTagJFH Offline
        HashTagJFH Offline
        HashTagJF
        wrote on last edited by
        #3

        The Cancel button. When I unchecked the checkbox then click cancel the checkbox should still be checked since there's no changes that has been made but when I re open it, it remains unchecked.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Do you mean when you start your application again ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          HashTagJFH 1 Reply Last reply
          0
          • A Offline
            A Offline
            ambershark
            wrote on last edited by ambershark
            #5

            That code is flawed. What if the user did not change the checkbox before hitting cancel? You are forcing a toggle basically when it's potential it wasn't clicked.

            You should track the original state in a variable until either ok or cancel is pressed. If cancel, return it to it's original state, if ok, honor the change.

            And finally, it does sound that you are trying to have a checkbox value persist after the app closes and reopens. If this is the case you need to save it's value somewhere. Check into QSettings for an easy way to handle serialization of options.

            My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

            1 Reply Last reply
            0
            • SGaistS SGaist

              Do you mean when you start your application again ?

              HashTagJFH Offline
              HashTagJFH Offline
              HashTagJF
              wrote on last edited by
              #6

              @SGaist yes when I start my application again..

              1 Reply Last reply
              0
              • HashTagJFH Offline
                HashTagJFH Offline
                HashTagJF
                wrote on last edited by
                #7

                my project is like this..
                0_1480570478181_upload-317a5dfc-c5e7-4c4f-af95-3b989b4434a2

                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #8

                  @ambershark still has a point. Changing something that hasn't been modified is just plain wrong.

                  The use QSetting to store and load the state of the widget.

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  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