How to implement PyQt widgets

Hello,

how to use widgets? i have plenty of examples, but i can`t load and set a widget…

import sys

from PyQt6.QtWidgets import (
    QApplication,
    QDialog,
    QDialogButtonBox,
    QLabel,
    QMainWindow,
    QPushButton,
    QVBoxLayout,
)


class CustomDialog(QDialog):
    def __init__(self, parent=None):  # <1>
        super().__init__(parent)

        self.setWindowTitle("HELLO!")

        buttons = (
            QDialogButtonBox.StandardButton.Ok
            | QDialogButtonBox.StandardButton.Cancel
        )

        self.buttonBox = QDialogButtonBox(buttons)
        self.buttonBox.accepted.connect(self.accept)
        self.buttonBox.rejected.connect(self.reject)

        self.layout = QVBoxLayout()
        message = QLabel("Something happened, is that OK?")
        self.layout.addWidget(message)
        self.layout.addWidget(self.buttonBox)
        self.setLayout(self.layout)




class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()

        self.setWindowTitle("My App")

        button = QPushButton("Press me for a dialog!")
        button.clicked.connect(self.button_clicked)
        self.setCentralWidget(button)

    # tag::button_clicked[]

    def button_clicked(self, s):
        print("click", s)

        dlg = CustomDialog(self)
        if dlg.exec():
            print("Success!")
        else:
            print("Cancel!")

    # end::button_clicked[]


app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

or is PyQt not accessable via PyRevit at all?

KR

Andreas

This should clarify _not a clear No, but more like ‘good luck trying’

1 Like

@Jean-Marc ,

secound option is SharpDevelop (C#)… ICSharpCode · GitHub

i see at EF-Tools. → Realy nice interfaces… in the folder there is the script and XAML file. how the hell does this work…?

…in PyQt they use a built.py and main.py file…

grafik

KR
Andreas

I’ll let @ErikFrits reply :wink:

1 Like

@Jean-Marc ,

i am already in his course www.learnRevitAPI.com :wink: i use all my resources !

f.e. in python courses (like https://www.udemy.com/) they support PyQt, it is well explaned, but when i want to implement it. It is a other topic. i know XAML is related to C# → WPF. I would require learn C#.

KR

Andreas