- PyQt - QPixmap Class
- PyQt - QClipboard
- PyQt - BrushStyle Constants
- PyQt - Drawing API
- PyQt - Database Handling
- PyQt - Drag and Drop
- PyQt - Multiple Document Interface
- PyQt - QMessageBox
- PyQt - QDialog Class
- PyQt - Basic Widgets
- PyQt - Layout Management
- PyQt - Signals and Slots
- PyQt - Using Qt Designer
- PyQt - Major Classes
- PyQt - Hello World
- PyQt - Introduction
- PyQt - Home
PyQt Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
PyQt - 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 PyQt4.QtGui import * from PyQt4.QtCore import * def window(): app = QApppcation(sys.argv) w = QWidget() b = QPushButton(w) b.setText("Hello World!") b.move(50,50) b.cpcked.connect(showdialog) w.setWindowTitle("PyQt Dialog demo") w.show() sys.exit(app.exec_()) def showdialog(): d = QDialog() b1 = QPushButton("ok",d) b1.move(50,50) d.setWindowTitle("Dialog") d.setWindowModapty(Qt.ApppcationModal) d.exec_() if __name__ == __main__ : window()
The above code produces the following output −
Advertisements