(value) # acessing DialogClass object that you passed while calling show modal Self.accept() #instead of close use its accept feature Self.exec_() # Use exec if you want to really want to create modal dialog Modal_(self.changeText) #connect signal and slotįull reference: Support for Signals and Slotsī(partial(nfirm,parent)) #using partial to make a slot alog with parameters Let's use them in the Dialog's showModal, after connecting the changeText slot and the Modal confirmed signal: def showModal(self): The slot function will receive the text in its t argument, and set the label text accordingly, but for this to happen the signal and the slot must be connected.įirst, let's edit the Modal class constructor, and remove this last two lines: tModal(True) To catch the signal, the other class need a slot: class Dialog(QDialog): (value) #emit the signal, passing the text as its only argument The signal has one argument of type str and will be emitted from the confirm slot, after reading from the line edit the text entered by the user: def confirm(self): You could send a signal from a dialog and catch it in the other.ĭefine a signal in the emitting dialog, using pyqtSignal: class Modal(QDialog): Self.label = QLabel('Default text value') How to pass the user text value to the first dialog? from PyQt5.QtGui import *īutton = QPushButton('Show modal dialog') When returned the first dialog uses it to replace label's 'Default text value'. The second dialog closes returning the user entered text. User enters a text in to the text field and clicks 'Confirm' button. The code below creates a dialog window with a QLabel and a single QPushButton.Ĭlicking the button brings up a second dialog with a text field and Confirm button.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |