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 485 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.
  • A Offline
    A Offline
    Anmol
    wrote on 22 Feb 2024, 07:08 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

    J R 2 Replies Last reply 22 Feb 2024, 07:13
    0
    • A Anmol
      22 Feb 2024, 07:08

      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

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 22 Feb 2024, 07:13 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

      A 1 Reply Last reply 22 Feb 2024, 08:13
      1
      • A Anmol
        22 Feb 2024, 07:08

        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

        R Offline
        R Offline
        Ronel_qtmaster
        wrote on 22 Feb 2024, 07:14 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
        • A Anmol has marked this topic as solved on 22 Feb 2024, 08:12
        • J jsulm
          22 Feb 2024, 07:13

          @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.

          A Offline
          A Offline
          Anmol
          wrote on 22 Feb 2024, 08:13 last edited by
          #4

          @jsulm ahh.. got it 😄. Thank you

          1 Reply Last reply
          0

          1/4

          22 Feb 2024, 07:08

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved