extension.py

"""PySide6 port of the widgets/dialogs/extension example from Qt v5.x"""

from PySide6 import QtCore, QtWidgets


class FindDialog(QtWidgets.QDialog):
    def __init__(self, parent=None):
        super(FindDialog, self).__init__(parent)

        label = QtWidgets.QLabel("Find &what:")
        lineEdit = QtWidgets.QLineEdit()
        label.setBuddy(lineEdit)

        caseCheckBox = QtWidgets.QCheckBox("Match &case")
        fromStartCheckBox = QtWidgets.QCheckBox("Search from &start")
        fromStartCheckBox.setChecked(True)

        findButton = QtWidgets.QPushButton("&Find")
        findButton.setDefault(True)

        moreButton = QtWidgets.QPushButton("&More")
        moreButton.setCheckable(True)
        moreButton.setAutoDefault(False)

        buttonBox = QtWidgets.QDialogButtonBox(QtCore.Qt.Vertical)
        buttonBox.addButton(findButton, QtWidgets.QDialogButtonBox.ActionRole)
        buttonBox.addButton(moreButton, QtWidgets.QDialogButtonBox.ActionRole)

        extension = QtWidgets.QWidget()

        wholeWordsCheckBox = QtWidgets.QCheckBox("&Whole words")
        backwardCheckBox = QtWidgets.QCheckBox("Search &backward")
        searchSelectionCheckBox = QtWidgets.QCheckBox("Search se&lection")

        moreButton.toggled.connect(extension.setVisible)

        extensionLayout = QtWidgets.QVBoxLayout()
        extensionLayout.setContentsMargins(0, 0, 0, 0)
        extensionLayout.addWidget(wholeWordsCheckBox)
        extensionLayout.addWidget(backwardCheckBox)
        extensionLayout.addWidget(searchSelectionCheckBox)
        extension.setLayout(extensionLayout)

        topLeftLayout = QtWidgets.QHBoxLayout()
        topLeftLayout.addWidget(label)
        topLeftLayout.addWidget(lineEdit)

        leftLayout = QtWidgets.QVBoxLayout()
        leftLayout.addLayout(topLeftLayout)
        leftLayout.addWidget(caseCheckBox)
        leftLayout.addWidget(fromStartCheckBox)
        leftLayout.addStretch(1)

        mainLayout = QtWidgets.QGridLayout()
        mainLayout.setSizeConstraint(QtWidgets.QLayout.SetFixedSize)
        mainLayout.addLayout(leftLayout, 0, 0)
        mainLayout.addWidget(buttonBox, 0, 1)
        mainLayout.addWidget(extension, 1, 0, 1, 2)
        self.setLayout(mainLayout)

        self.setWindowTitle("Extension")
        extension.hide()


if __name__ == '__main__':

    import sys

    app = QtWidgets.QApplication(sys.argv)
    dialog = FindDialog()
    sys.exit(dialog.exec_())