Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here's a simple example. Each <code>QRadioButton</code> is connected to it's own function. You could connect them both to the same function and manage what happens through that, but I thought best to demonstrate how the signals and slots work.</p> <p>For more info, take a look at the PyQt4 <a href="http://pyqt.sourceforge.net/Docs/PyQt4/new_style_signals_slots.html" rel="noreferrer">documentation for new style signals and slots</a>. If connecting multiple signals to the same slot it's sometimes useful to use the <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qobject.html#sender" rel="noreferrer"><code>.sender()</code></a> method of a <code>QObject</code>, although in the case of <code>QRadioButton</code> it's probably easier to just check the <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qabstractbutton.html#isChecked" rel="noreferrer">.isChecked()</a> method of your desired buttons.</p> <pre><code>import sys from PyQt4.QtGui import QApplication, QWidget, QVBoxLayout, \ QLineEdit, QRadioButton class Widget(QWidget): def __init__(self, parent=None): QWidget.__init__(self, parent) self.widget_layout = QVBoxLayout() self.radio1 = QRadioButton('Radio 1') self.radio2 = QRadioButton('Radio 2') self.line_edit = QLineEdit() self.radio1.toggled.connect(self.radio1_clicked) self.radio2.toggled.connect(self.radio2_clicked) self.widget_layout.addWidget(self.radio1) self.widget_layout.addWidget(self.radio2) self.widget_layout.addWidget(self.line_edit) self.setLayout(self.widget_layout) def radio1_clicked(self, enabled): if enabled: self.line_edit.setText('Radio 1') def radio2_clicked(self, enabled): if enabled: self.line_edit.setText('Radio 2') if __name__ == '__main__': app = QApplication(sys.argv) widget = Widget() widget.show() sys.exit(app.exec_()) </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload