Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. How to implement the functionality of “Don’t ask again ” dialog in PyQt4 ?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Language Bindings
2 Posts 2 Posters 2.0k 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.
  • R Offline
    R Offline
    redstoneleo
    wrote on last edited by
    #1

    It would be great to explain it by By example 

    1 Reply Last reply
    0
    • jazzycamelJ Offline
      jazzycamelJ Offline
      jazzycamel
      wrote on last edited by
      #2

      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_())
      @

      For the avoidance of doubt:

      1. All my code samples (C++ or Python) are tested before posting
      2. As of 23/03/20, my Python code is formatted to PEP-8 standards using black from the PSF (https://github.com/psf/black)
      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