0

I am working on pyqt5 gui. I am trying to understand the usage of pyqtsignal in python. I got a link on youtube- https://www.youtube.com/watch?v=LfztdwaGOjs&list=LL&index=1. The video is in spanish(i don't understand spanish). I typed the code. It runs as expected, but I am not able to understand how to use pyqtsignal, where to use, how to use it.

dialog.py

from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from PyQt5 import uic

class Dialog(QDialog):
    listWidgetTieneMultiploDe5= pyqtSignal()

    def __init__(self):
        QDialog.__init__(self)
        uic.loadUi("dialog.ui",self)

        self.agregarButton.clicked.connect(self.onAgregarButtonClicked)

        self.listWidgetTieneMultiploDe5.connect(self.onListWidgetTienemultiploDe5)


    def onAgregarButtonClicked(self):
        self.listWidget.addItem("Hola, mundo")

        if self.listWidget.count()%5 == 0:
            self.listWidgetTieneMultiploDe5.emit()


    def onListWidgetTienemultiploDe5(self):
        QMessageBox.information(self,"OK","Muliple de 5")

main.py

from PyQt5.QtWidgets import QApplication
from dialog import Dialog
import sys

app= QApplication(sys.argv)
app.setStyle("fusion")
w=Dialog()
w.show()
sys.exit(app.exec_())

dialog.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>480</width>
    <height>384</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Dialog</string>
  </property>
  <layout class="QGridLayout" name="gridLayout">
   <item row="0" column="0">
    <widget class="QPushButton" name="agregarButton">
     <property name="text">
      <string>Agregar</string>
     </property>
    </widget>
   </item>
   <item row="1" column="0">
    <widget class="QListWidget" name="listWidget"/>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections/>
</ui>

The result of the code:

Result of the above Code

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • Also read https://www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html and https://doc.qt.io/qt-5/signalsandslots.html – eyllanesc Oct 21 '20 at 17:19
  • Avoid putting irrelevant information as if you are new to some technology, SO helps solve problems without relying on who asks. Also, do not ask for external resources such as links since it is off-topic. Please read the links that I already indicated in the other post: [ask], [answer] and [tour] – eyllanesc Oct 21 '20 at 17:21
  • Thank you eyllanesc. This is a great help. – Manu Chaudhary Oct 21 '20 at 17:46

0 Answers0