"Don't show this meesage again" checkbox in QMessagebox
-
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.
@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")
-
@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")
@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?
-
@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?
@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.
-
@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.
@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.
-
@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.
-
@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.
Then you need to store something like
QSettings
.
So that your app will know what your settings from your last run are. -
@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?
-
Hi,
Please read the function documentation. There are examples shown there on how it works.
QSettings works on the key/value paradigm.
-
@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?
@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...
-
@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...
@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?
-
@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?
@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...
-
@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?
@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? -
@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?@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?
-
@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?
@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? -
@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?@JonB I have read the value from registry as I said using this line -->
settings = QtCore.QSettings('ConTest', 'Check-Box status') settings.setValue("check_box_status", check_box_status) value = settings.value('check_box_status', check_box_status)
So the 1st line will create a folder in registry by the name Check_box_status
2nd line will store the value of chwck-box in registry and the 3rd line will read that value back from registry. Now my question is how to use this value to not show the pop-up again. -
Hi,
The logic has already been explained several times:
- Get the settings value
- Check what that value is
- Show or not the message box based on this value
- If the message box has been show, update the settings value
In any case, you really should use more meaningful variable and key names. It would help you quite a lot with the code flow.
-
Hi,
The logic has already been explained several times:
- Get the settings value
- Check what that value is
- Show or not the message box based on this value
- If the message box has been show, update the settings value
In any case, you really should use more meaningful variable and key names. It would help you quite a lot with the code flow.
@SGaist That is what my question is actually. The logic is understood, but the 3rd point u have mentioned is the actual problem. How to use this value to not show the pop-up. That is what I want to know.
-
@SGaist That is what my question is actually. The logic is understood, but the 3rd point u have mentioned is the actual problem. How to use this value to not show the pop-up. That is what I want to know.
@Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:
but the 3rd point u have mentioned is the actual problem
The third point is a simple if () statement checking the value of the setting...
-
@Prathamesh said in "Don't show this meesage again" checkbox in QMessagebox:
but the 3rd point u have mentioned is the actual problem
The third point is a simple if () statement checking the value of the setting...
@jsulm Of course it is if statement, my question was not about how to check the value. My question was how to use that value to show message-box or not to show it. I hope this time it is clear.
-
@jsulm Of course it is if statement, my question was not about how to check the value. My question was how to use that value to show message-box or not to show it. I hope this time it is clear.
How you would do it without
QSettings
? Same thing. Doesn't matter where thebool
is coming from. Set it somewhere (member / class var) and then put the check before the code that shows the messageBox.
I don't see any problem or difficulty there...