from qgis.PyQt.QtWidgets import QDialog, QVBoxLayout, QPushButton class MyDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) layout = QVBoxLayout() ok_button = QPushButton('OK') cancel_button = QPushButton('Cancel') layout.addWidget(ok_button) layout.addWidget(cancel_button) self.setLayout(layout)
from qgis.PyQt.QtWidgets import QDialog, QHBoxLayout, QLabel, QLineEdit, QPushButton class CustomDialog(QDialog): def __init__(self, parent=None): super().__init__(parent) layout = QHBoxLayout() label = QLabel('Enter your name:') self.name_input = QLineEdit() button = QPushButton('OK') button.clicked.connect(self.submit) layout.addWidget(label) layout.addWidget(self.name_input) layout.addWidget(button) self.setLayout(layout) def submit(self): name = self.name_input.text() print(f'Hello, {name}!') self.accept()In this example, we create a custom QDialog called "CustomDialog" with a label and a text input field for the user to enter their name. When the user clicks the "OK" button, we retrieve the name from the text input field, print a greeting, and call "self.accept()" to close the dialog box. We use an QHBoxLayout to organize the label, text input field, and button horizontally. Package library: PyQt5.