- PyQt5 - Discussion
- PyQt5 - Useful Resources
- PyQt5 - Quick Guide
- PyQt5 - QPixmap Class
- PyQt5 - QClipboard
- PyQt5 - BrushStyle Constants
- PyQt5 - Drawing API
- PyQt5 - Database Handling
- PyQt5 - Drag & Drop
- PyQt5 - Multiple Document Interface
- PyQt5 - QMessageBox
- PyQt5 - QDialog Class
- PyQt5 - Basic Widgets
- PyQt5 - Layout Management
- PyQt5 - Signals & Slots
- PyQt5 - Using Qt Designer
- PyQt5 - Major Classes
- PyQt5 - Hello World
- PyQt5 - What’s New
- PyQt5 - Introduction
- PyQt5 - Home
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyQt5 - QDialog Class
A QDialog widget presents a top level window mostly used to collect response from the user. It can be configured to be Modal (where it blocks its parent window) or Modeless (the dialog window can be bypassed).
PyQt API has a number of preconfigured Dialog widgets such as InputDialog, FileDialog, FontDialog, etc.
Example
In the following example, WindowModapty attribute of Dialog window decides whether it is modal or modeless. Any one button on the dialog can be set to be default. The dialog is discarded by QDialog.reject() method when the user presses the Escape key.
A PushButton on a top level QWidget window, when cpcked, produces a Dialog window. A Dialog box doesn’t have minimize and maximize controls on its title bar.
The user cannot relegate this dialog box in the background because its WindowModapty is set to ApppcationModal.
import sys from PyQt5.QtCore import * from PyQt5.QtGui import * from PyQt5.QtWidgets import * def window(): app = QApppcation(sys.argv) w = QWidget() btn = QPushButton(w) btn.setText("Hello World!") btn.move(100,50) btn.cpcked.connect(showdialog) w.setWindowTitle("PyQt Dialog demo") w.show() sys.exit(app.exec_()) def showdialog(): dlg = QDialog() b1 = QPushButton("ok",dlg) b1.move(50,50) dlg.setWindowTitle("Dialog") 9. PyQt5 — QDialog Class dlg.setWindowModapty(Qt.ApppcationModal) dlg.exec_() if __name__ == __main__ : window()
The above code produces the following output. Cpck on button in main window and dialog box pops up −
Advertisements