How to implement the functionality of “Don’t ask again ” dialog in PyQt4 ?



  • It would be great to explain it by By example 



  • The following example probably does what you want. If you want to remember the choice for the future, use [[doc:QSettings]].

    @
    from PyQt4.QtCore import *
    from PyQt4.QtGui import *

    class Dialog(QDialog):
    def init(self, parent=None):
    QDialog.init(self, parent)

        l=QVBoxLayout(self)
        l.addWidget(QLabel("A nice little dialog", self))
    
        self.dontShowCBox=QCheckBox("Don't show this dialog again")
        l.addWidget(self.dontShowCBox)
    
        l.addWidget(QDialogButtonBox(
                        QDialogButtonBox.Ok|QDialogButtonBox.Cancel, 
                        parent=self, 
                        accepted=self.accept, 
                        rejected=self.reject))
    
    @staticmethod
    def dialog(parent):
        d=Dialog(parent)
        if d.exec_(): return True, not d.dontShowCBox.isChecked()
        else: return False, False
    

    class Widget(QWidget):
    def init(self, parent=None):
    QWidget.init(self, parent)

        self._prompt=True
    
        l=QVBoxLayout(self)
        l.addWidget(QPushButton("Button", self, clicked=self.dialogRequested))
    
    @pyqtSlot()
    def dialogRequested(self):
        if not self._prompt: return
        ok, prompt=Dialog.dialog(self)
        if ok: self._prompt=prompt
    

    if name=="main":
    from sys import argv, exit
    a=QApplication(argv)
    w=Widget()
    w.show()
    w.raise_()
    exit(a.exec_())
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.