Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>At first, here is the minimal working example:</p> <pre><code>from sys import argv, exit from PyQt4 import QtCore, QtGui class widget2(QtGui.QWidget): def __init__(self, args): self.app = MainApp(args) QtGui.QWidget.__init__(self) self.setObjectName('I') self._layout = QtGui.QVBoxLayout(self) self.setLayout(self._layout) self.pushButtoninWidget2 = QtGui.QPushButton(self) self.pushButtoninWidget2.setObjectName("pushButtoninWidget2") self.pushButtoninWidget2.setText('Click NOW!') self._layout.addWidget(self.pushButtoninWidget2) QtCore.QMetaObject.connectSlotsByName(self) @QtCore.pyqtSlot() def on_pushButtoninWidget2_clicked(self): print("Hai") class MainApp(QtGui.QApplication): def __init__(self, args): QtGui.QApplication.__init__(self, args) if __name__ == "__main__": main = widget2(argv) main.show() exit(main.app.exec_()) </code></pre> <p>When you trying to connect slots by name, you must give proper names to the slots and then someone (moc, uic, or you by calling connectSlotsByName) must connect them. Proper name for such a slot is: "on_PyQtObjectName_PyQtSignalName".</p> <p>Note, that, if I'd omitted @QtCore.pyqtSlot() in the example, slot would be executed once for every appropriate overload (twice in this case).</p> <p>You DO need to call connectSlotsByNames directly, cause there is no moc, which do it for you when you use QT in C++, and you do not use uic and .ui file. If you want to connect slots implicitly (I'm always doing so, except slots, connected directly in .ui), you'd better use more pytonish syntaxe: button.clicked.connect(self._mySlot).</p> <p>And take a look at <a href="http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#connecting-slots-by-name" rel="nofollow noreferrer">http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/pyqt4ref.html#connecting-slots-by-name</a></p>
    singulars
    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. 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.
 

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