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. "Don't show this meesage again" checkbox in QMessagebox
Forum Updated to NodeBB v4.3 + New Features

"Don't show this meesage again" checkbox in QMessagebox

Scheduled Pinned Locked Moved Unsolved General and Desktop
38 Posts 8 Posters 3.0k Views 3 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.
  • P Prathamesh

    @jsulm Ok,
    state = check_box.checkState()
    if state == Qt.Checked:
    pass

    Now is it ok or am I still missing something? because it is appearing again..

    jsulmJ Offline
    jsulmJ Offline
    jsulm
    Lifetime Qt Champion
    wrote on last edited by
    #8

    @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

    if state == Qt.Checked:
    pass

    What do you want to achieve with this useless code?
    Don't you think you should also check the stored state of the check box BEFORE showing ther dialog? As I suggested?

    https://forum.qt.io/topic/113070/qt-code-of-conduct

    1 Reply Last reply
    2
    • P Prathamesh

      @jsulm Ok,
      state = check_box.checkState()
      if state == Qt.Checked:
      pass

      Now is it ok or am I still missing something? because it is appearing again..

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

      @Prathamesh
      And in addition to @jsulm's comment: if you want to know the user previously checked the box so that you don't show the dialog again, you are going to have save somewhere in persistent state that the user previously checked that box. You can't get that from the dialog previously, because you create a new dialog each time.

      P 1 Reply Last reply
      2
      • JonBJ JonB

        @Prathamesh
        And in addition to @jsulm's comment: if you want to know the user previously checked the box so that you don't show the dialog again, you are going to have save somewhere in persistent state that the user previously checked that box. You can't get that from the dialog previously, because you create a new dialog each time.

        P Offline
        P Offline
        Prathamesh
        wrote on last edited by
        #10

        @JonB Checked all the methods given in documentation, tried to store checkbox status in a variable. But same thing is happening.

        JonBJ 1 Reply Last reply
        0
        • P Prathamesh

          @JonB Checked all the methods given in documentation, tried to store checkbox status in a variable. But same thing is happening.

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

          @Prathamesh It's your code then.

          P 1 Reply Last reply
          0
          • J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #12

            Here's one way to do something like this:

            int main(int argc, char *argv[])
            {
            
                QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
                QCoreApplication::setOrganizationName("MyCompany");
                QCoreApplication::setOrganizationDomain("MyApplication");
                QApplication app(argc, argv);
            
            
                QSettings s;
            
                QMessageBox msgB(QMessageBox::Critical,"One TimeBox", "This MessageBox, when confirmed will never be shown again");
            
                msgB.setStandardButtons(QMessageBox::Ok | QMessageBox::Cancel);
            
                QTimer t;
                t.setSingleShot(true);
            
                if(!s.value("OneTimeOK",false).toBool()){
                    
                    QObject::connect(&t, &QTimer::timeout,&msgB, &QMessageBox::exec);
            
                    QObject::connect(&msgB, &QMessageBox::finished, [&s,&t, &app](int result){
                        qDebug() << "Finished" << result;
                        if(result == QMessageBox::Ok){
                            s.setValue("OneTimeOK", true);
                            app.quit();
                        } else {
                            t.start(1000);
                        }
            
                    });
                    msgB.exec();
                } else {
                    qDebug() << "Nothing to show";
                    return -1;
                }
            
                return app.exec();
            }
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • JonBJ JonB

              @Prathamesh It's your code then.

              P Offline
              P Offline
              Prathamesh
              wrote on last edited by
              #13

              @JonB

              def __gui_initial_state(self):
                  """
                  This method initializes the gui state.
                  """
                  self.initial_state.emit()
                  self.__update_recent_configurations()
                  version_str, version_tuple = global_vars.check_latest_version()
                           
                  if global_vars.LOCAL_VERSION_TUPLE >= version_tuple:
                      msg = QtWidgets.QMessageBox()
                      msg.setWindowTitle("What's New")
                      msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                      msg.setWindowIcon(QtGui.QIcon(os.path.abspath(os.path.join(os.path.dirname(
                          os.path.realpath(__file__)), 'gui_images', 'logo_icon.png'))))
                      msg.setText(ui_helper.WHAT_IS_NEW)
                      check_box = QtWidgets.QCheckBox("Don't show this again")
                      msg.setCheckBox(check_box)
                      msg.exec_()
                      check_box_status = check_box.isChecked()
                      if check_box_status:
                          print("abcd")
              

              This method executes everytime when a gui in launched. My task is to check whether new version of framework is launched or not, and if launched user will download it. After downloading my code will check if it is downloaded and then a pop-up containing all the information about new version will come up.

              So,this pop-up will appear first time when user downloads new version, and then in this pop-up i have to put a checkbox. So I have done that,and using ischecked() method its status is getting stored in a variable and as i have written print("abcd") if status is true. So it is working fine.

              But the problem is, everytime a gui is launched this pop-up will come up,so even after storing True status from previos run ,it is appearing. I am not understanding how to handle this situation.

              jsulmJ 1 Reply Last reply
              0
              • P Prathamesh

                @JonB

                def __gui_initial_state(self):
                    """
                    This method initializes the gui state.
                    """
                    self.initial_state.emit()
                    self.__update_recent_configurations()
                    version_str, version_tuple = global_vars.check_latest_version()
                             
                    if global_vars.LOCAL_VERSION_TUPLE >= version_tuple:
                        msg = QtWidgets.QMessageBox()
                        msg.setWindowTitle("What's New")
                        msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                        msg.setWindowIcon(QtGui.QIcon(os.path.abspath(os.path.join(os.path.dirname(
                            os.path.realpath(__file__)), 'gui_images', 'logo_icon.png'))))
                        msg.setText(ui_helper.WHAT_IS_NEW)
                        check_box = QtWidgets.QCheckBox("Don't show this again")
                        msg.setCheckBox(check_box)
                        msg.exec_()
                        check_box_status = check_box.isChecked()
                        if check_box_status:
                            print("abcd")
                

                This method executes everytime when a gui in launched. My task is to check whether new version of framework is launched or not, and if launched user will download it. After downloading my code will check if it is downloaded and then a pop-up containing all the information about new version will come up.

                So,this pop-up will appear first time when user downloads new version, and then in this pop-up i have to put a checkbox. So I have done that,and using ischecked() method its status is getting stored in a variable and as i have written print("abcd") if status is true. So it is working fine.

                But the problem is, everytime a gui is launched this pop-up will come up,so even after storing True status from previos run ,it is appearing. I am not understanding how to handle this situation.

                jsulmJ Offline
                jsulmJ Offline
                jsulm
                Lifetime Qt Champion
                wrote on last edited by
                #14

                @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                But the problem is, everytime a gui is launched this pop-up will come up,so even after storing True status from previos run

                Of course, you are still not doing what was suggested!

                def __gui_initial_state(self):
                    """
                    This method initializes the gui state.
                    """
                    self.initial_state.emit()
                    self.__update_recent_configurations()
                    version_str, version_tuple = global_vars.check_latest_version()
                             
                    if global_vars.LOCAL_VERSION_TUPLE >= version_tuple and not self.__check_box_status:
                        msg = QtWidgets.QMessageBox()
                        msg.setWindowTitle("What's New")
                        msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                        msg.setWindowIcon(QtGui.QIcon(os.path.abspath(os.path.join(os.path.dirname(
                            os.path.realpath(__file__)), 'gui_images', 'logo_icon.png'))))
                        msg.setText(ui_helper.WHAT_IS_NEW)
                        check_box = QtWidgets.QCheckBox("Don't show this again")
                        msg.setCheckBox(check_box)
                        msg.exec_()
                        self.__check_box_status = check_box.isChecked()
                        if self.__check_box_status:
                            print("abcd")
                

                https://forum.qt.io/topic/113070/qt-code-of-conduct

                P 1 Reply Last reply
                0
                • jsulmJ jsulm

                  @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                  But the problem is, everytime a gui is launched this pop-up will come up,so even after storing True status from previos run

                  Of course, you are still not doing what was suggested!

                  def __gui_initial_state(self):
                      """
                      This method initializes the gui state.
                      """
                      self.initial_state.emit()
                      self.__update_recent_configurations()
                      version_str, version_tuple = global_vars.check_latest_version()
                               
                      if global_vars.LOCAL_VERSION_TUPLE >= version_tuple and not self.__check_box_status:
                          msg = QtWidgets.QMessageBox()
                          msg.setWindowTitle("What's New")
                          msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                          msg.setWindowIcon(QtGui.QIcon(os.path.abspath(os.path.join(os.path.dirname(
                              os.path.realpath(__file__)), 'gui_images', 'logo_icon.png'))))
                          msg.setText(ui_helper.WHAT_IS_NEW)
                          check_box = QtWidgets.QCheckBox("Don't show this again")
                          msg.setCheckBox(check_box)
                          msg.exec_()
                          self.__check_box_status = check_box.isChecked()
                          if self.__check_box_status:
                              print("abcd")
                  
                  P Offline
                  P Offline
                  Prathamesh
                  wrote on last edited by
                  #15

                  @jsulm I did half part of storing status.But I am not getting how to check it while launching a gui next time? That is where I am stuck. Any suggesstion please?

                  jsulmJ 1 Reply Last reply
                  0
                  • P Prathamesh

                    @jsulm I did half part of storing status.But I am not getting how to check it while launching a gui next time? That is where I am stuck. Any suggesstion please?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by
                    #16

                    @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                    how to check it while launching a gui next time?

                    What exactly do you mean by that? Do you mean you close the app and then start it again and you want to check this check status? If so, then use QSettings to store such information permanently.

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    P 1 Reply Last reply
                    2
                    • jsulmJ jsulm

                      @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                      how to check it while launching a gui next time?

                      What exactly do you mean by that? Do you mean you close the app and then start it again and you want to check this check status? If so, then use QSettings to store such information permanently.

                      P Offline
                      P Offline
                      Prathamesh
                      wrote on last edited by
                      #17

                      @jsulm yeah this is what I mean exactly. Once I tick a checkbox and close an app then pop-up should not appear until new version of framework is launched.

                      jsulmJ Pl45m4P 2 Replies Last reply
                      0
                      • P Prathamesh

                        @jsulm yeah this is what I mean exactly. Once I tick a checkbox and close an app then pop-up should not appear until new version of framework is launched.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #18

                        @Prathamesh https://doc.qt.io/qt-5/qsettings.html

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        P 1 Reply Last reply
                        3
                        • P Prathamesh

                          @jsulm yeah this is what I mean exactly. Once I tick a checkbox and close an app then pop-up should not appear until new version of framework is launched.

                          Pl45m4P Offline
                          Pl45m4P Offline
                          Pl45m4
                          wrote on last edited by Pl45m4
                          #19

                          @Prathamesh

                          Then you need to store something like QSettings.
                          So that your app will know what your settings from your last run are.

                          • https://doc.qt.io/qt-5/qsettings.html#basic-usage
                          • https://doc.qt.io/qt-5/qsettings.html#restoring-the-state-of-a-gui-application

                          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                          ~E. W. Dijkstra

                          1 Reply Last reply
                          1
                          • jsulmJ jsulm

                            @Prathamesh https://doc.qt.io/qt-5/qsettings.html

                            P Offline
                            P Offline
                            Prathamesh
                            wrote on last edited by
                            #20

                            @jsulm Thanks for this. I have tried this just now. I have written something like this

                            --> msg = QtWidgets.QMessageBox()
                            msg.setWindowTitle("What's New")
                            msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                            msg.setText(ui_helper.WHAT_IS_NEW)
                            check_box = QtWidgets.QCheckBox("Don't show this again")
                            msg.setCheckBox(check_box)
                            msg.exec_()
                            check_box_status = check_box.isChecked()
                            settings = QtCore.QSettings()
                            settings.setValue(check_box_status, True)

                            I know this is not the correct way of doing and that's why I am getting an error --> setValue has unexpected type 'bool'. But then how do I pass the status of checkbox into this function?

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

                              Hi,

                              Please read the function documentation. There are examples shown there on how it works.

                              QSettings works on the key/value paradigm.

                              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
                              1
                              • P Prathamesh

                                @jsulm Thanks for this. I have tried this just now. I have written something like this

                                --> msg = QtWidgets.QMessageBox()
                                msg.setWindowTitle("What's New")
                                msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                                msg.setText(ui_helper.WHAT_IS_NEW)
                                check_box = QtWidgets.QCheckBox("Don't show this again")
                                msg.setCheckBox(check_box)
                                msg.exec_()
                                check_box_status = check_box.isChecked()
                                settings = QtCore.QSettings()
                                settings.setValue(check_box_status, True)

                                I know this is not the correct way of doing and that's why I am getting an error --> setValue has unexpected type 'bool'. But then how do I pass the status of checkbox into this function?

                                jsulmJ Offline
                                jsulmJ Offline
                                jsulm
                                Lifetime Qt Champion
                                wrote on last edited by
                                #22

                                @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                                settings.setValue(check_box_status, True)

                                Please read documentation to know how to do it properly, there are even code examples...

                                https://forum.qt.io/topic/113070/qt-code-of-conduct

                                P 1 Reply Last reply
                                1
                                • jsulmJ jsulm

                                  @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                                  settings.setValue(check_box_status, True)

                                  Please read documentation to know how to do it properly, there are even code examples...

                                  P Offline
                                  P Offline
                                  Prathamesh
                                  wrote on last edited by
                                  #23

                                  @jsulm So I have read the documentation and from that i got to know that QSettings will store the value in registry editor in our machine. So I have written a code like below-->

                                  msg = QtWidgets.QMessageBox()
                                  msg.setWindowTitle("What's New")
                                  msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                                  msg.setText(ui_helper.WHAT_IS_NEW)
                                  check_box = QtWidgets.QCheckBox("Don't show this again")
                                  msg.setCheckBox(check_box)
                                  msg.exec_()
                                  check_box_status = check_box.isChecked()
                                  settings = QtCore.QSettings('ConTest', 'Check-Box status')
                                  settings.setValue("check_box_status", check_box_status)

                                  Now I can see the status of checkbox as true or false in the registry. I need help here. Whatever I have written in my code is correct or not? Because the pop-up is still appearing ,that means I am not making use of registry data. How can I do that in my code?

                                  jsulmJ JonBJ 2 Replies Last reply
                                  0
                                  • P Prathamesh

                                    @jsulm So I have read the documentation and from that i got to know that QSettings will store the value in registry editor in our machine. So I have written a code like below-->

                                    msg = QtWidgets.QMessageBox()
                                    msg.setWindowTitle("What's New")
                                    msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                                    msg.setText(ui_helper.WHAT_IS_NEW)
                                    check_box = QtWidgets.QCheckBox("Don't show this again")
                                    msg.setCheckBox(check_box)
                                    msg.exec_()
                                    check_box_status = check_box.isChecked()
                                    settings = QtCore.QSettings('ConTest', 'Check-Box status')
                                    settings.setValue("check_box_status", check_box_status)

                                    Now I can see the status of checkbox as true or false in the registry. I need help here. Whatever I have written in my code is correct or not? Because the pop-up is still appearing ,that means I am not making use of registry data. How can I do that in my code?

                                    jsulmJ Offline
                                    jsulmJ Offline
                                    jsulm
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #24

                                    @Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:

                                    Because the pop-up is still appearing

                                    Of course it does. You do not check what you stored in settings to decide whether you should show the dialog or not...

                                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    1
                                    • P Prathamesh

                                      @jsulm So I have read the documentation and from that i got to know that QSettings will store the value in registry editor in our machine. So I have written a code like below-->

                                      msg = QtWidgets.QMessageBox()
                                      msg.setWindowTitle("What's New")
                                      msg.setWindowFlags(QtCore.Qt.WindowStaysOnTopHint)
                                      msg.setText(ui_helper.WHAT_IS_NEW)
                                      check_box = QtWidgets.QCheckBox("Don't show this again")
                                      msg.setCheckBox(check_box)
                                      msg.exec_()
                                      check_box_status = check_box.isChecked()
                                      settings = QtCore.QSettings('ConTest', 'Check-Box status')
                                      settings.setValue("check_box_status", check_box_status)

                                      Now I can see the status of checkbox as true or false in the registry. I need help here. Whatever I have written in my code is correct or not? Because the pop-up is still appearing ,that means I am not making use of registry data. How can I do that in my code?

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

                                      @Prathamesh
                                      So your code now stores the desired value in the registry. What do you now do about reading that value back, and then acting on it for (not showing) the dialog?

                                      P 1 Reply Last reply
                                      0
                                      • JonBJ JonB

                                        @Prathamesh
                                        So your code now stores the desired value in the registry. What do you now do about reading that value back, and then acting on it for (not showing) the dialog?

                                        P Offline
                                        P Offline
                                        Prathamesh
                                        wrote on last edited by
                                        #26

                                        @JonB Ok , so I have stored the value from registry using .value() method as -->
                                        value = settings.value('check_box_status', check_box_status)

                                        Now how do I proceed further. Could you please guide me further?

                                        JonBJ 1 Reply Last reply
                                        0
                                        • P Prathamesh

                                          @JonB Ok , so I have stored the value from registry using .value() method as -->
                                          value = settings.value('check_box_status', check_box_status)

                                          Now how do I proceed further. Could you please guide me further?

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

                                          @Prathamesh
                                          You need to read the doc page and the examples. That's what development is about. They even show you how to read back a value, what have you done about that?

                                          P 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