Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How does Signal and slot works in this code
Forum Updated to NodeBB v4.3 + New Features

How does Signal and slot works in this code

Scheduled Pinned Locked Moved Solved Qt for Python
qt for pythonpysidepyside2python
4 Posts 3 Posters 487 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.
  • AnmolA Offline
    AnmolA Offline
    Anmol
    wrote on last edited by
    #1

    IMG_20240222_123630_427.jpg

    import sys
    from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton
    
    class MainWindow(QMainWindow):
      def __init__(self):
        super().__init__()
    
        self.setWindowTitle("My App")
        button = QPushButton("Press Me!")
        button.setCheckable(True)
    
        button.clicked.connect(self.the_button_was_toggled)
        
        # Set the central widget of the Window.
        self.setCentralWidget(button)
    
      def the_button_was_toggled(self, checked): # from where value of variable checked is coming and how?
        print("Checked?", checked)
    
    app = QApplication(sys.argv)
    window = MainWindow()
    window.show()
    
    app.exec()
    
    
    

    How does this code know the state of the button's checked value. From where it is accessing variable buttons and how

    jsulmJ Ronel_qtmasterR 2 Replies Last reply
    0
    • AnmolA Anmol

      IMG_20240222_123630_427.jpg

      import sys
      from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton
      
      class MainWindow(QMainWindow):
        def __init__(self):
          super().__init__()
      
          self.setWindowTitle("My App")
          button = QPushButton("Press Me!")
          button.setCheckable(True)
      
          button.clicked.connect(self.the_button_was_toggled)
          
          # Set the central widget of the Window.
          self.setCentralWidget(button)
      
        def the_button_was_toggled(self, checked): # from where value of variable checked is coming and how?
          print("Checked?", checked)
      
      app = QApplication(sys.argv)
      window = MainWindow()
      window.show()
      
      app.exec()
      
      
      

      How does this code know the state of the button's checked value. From where it is accessing variable buttons and how

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

      @Anmol Just look at the signal documentation: https://doc.qt.io/qt-6/qabstractbutton.html#clicked
      As you can see the signal has checked parameter which is passed to the slot.

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

      AnmolA 1 Reply Last reply
      1
      • AnmolA Anmol

        IMG_20240222_123630_427.jpg

        import sys
        from PySide6.QtWidgets import QApplication, QMainWindow, QPushButton
        
        class MainWindow(QMainWindow):
          def __init__(self):
            super().__init__()
        
            self.setWindowTitle("My App")
            button = QPushButton("Press Me!")
            button.setCheckable(True)
        
            button.clicked.connect(self.the_button_was_toggled)
            
            # Set the central widget of the Window.
            self.setCentralWidget(button)
        
          def the_button_was_toggled(self, checked): # from where value of variable checked is coming and how?
            print("Checked?", checked)
        
        app = QApplication(sys.argv)
        window = MainWindow()
        window.show()
        
        app.exec()
        
        
        

        How does this code know the state of the button's checked value. From where it is accessing variable buttons and how

        Ronel_qtmasterR Offline
        Ronel_qtmasterR Offline
        Ronel_qtmaster
        wrote on last edited by
        #3

        @Anmol if checked == true the button is checked, otherwise it is not checked. So depending on the value of checked bool variable you can apply some actions

        1 Reply Last reply
        0
        • AnmolA Anmol has marked this topic as solved on
        • jsulmJ jsulm

          @Anmol Just look at the signal documentation: https://doc.qt.io/qt-6/qabstractbutton.html#clicked
          As you can see the signal has checked parameter which is passed to the slot.

          AnmolA Offline
          AnmolA Offline
          Anmol
          wrote on last edited by
          #4

          @jsulm ahh.. got it 😄. Thank you

          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