Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

PySide2 with Qt Design Studio



  • I am trying to use the widgets made within Qt Design Studio inside PySide2. For eg, I made a simple button using Qt Design studio and I want to execute some function based on the clicked event triggered by the button. Is there a specific method by which we can use the UI generated in Qt Design Studio with PySide2.

    Demo Project Structure in Qt DS:

    Demo.qml
    Demo.qmlproject
    Demo.qmlproject.qtds
    imports
    qtquickcontrols2.conf
    Screen01.ui.qml

    PySide2 project structure:

    Demo.qml
    Demo.qmlproject
    Demo.qmlproject.qtds
    imports
    qtquickcontrols2.conf
    Screen01.ui.qml
    main.py

    main.py file:

    from PySide2.QtWidgets import QApplication, QMainWindow
    from PySide2.QtQuick import QQuickView
    from PySide2.QtCore import QUrl
    from imports import QtQuick
    app = QApplication([])
    view = QQuickView()
    url = QUrl("Screen01.ui.qml")
    view.engine().addImportPath("imports")
    view.setSource(url)
    view.show()
    app.exec_()

    Screen01.ui.qml file:

    import QtQuick 2.12
    import Demo 1.0
    import QtQuick.Controls 2.3

    Rectangle {
    width: Constants.width
    height: Constants.height

    color: Constants.backgroundColor
    
    Button {
        id: nameButton
        x: 136
        y: 227
        text: qsTr("Button")
    }
    

    }


  • Banned

    Okay do you understand the purpose for the Designer's code -- as I do not think you do. That being said unless you need a GUI that is code morphable then do not use the Designer to create your GUI it is horrible and barely even Qt-ish (aka it works but is not how a proper Qt GUI is made). Further you are going to have nothing but continuous headaches using it and it being black-box untouchable code means its very dangerous for any project. Lastly it takes more effort to learn to use the Designer correctly than it does to learn to use Qt (be it PySide2 or PyQt) correctly and it is just as easy and perhaps quicker, once you get the hang of it, to create a proper GUI using Qt as opposed to the Designer and you have something you can actually understand and work with when you are done.

    Also are you using straight Qt ? Or does the Designer you are using produce C++ code? Because that is not a PySide2/PyQt Button -- or is that an aspect of you using QML?


  • Lifetime Qt Champion

    @Denni-0 Qt Design Studio has nothing to do with the old Designer application.


  • Banned

    Oh okay well then disregard that aspect of my message but so far everything I have seen that seems to work along the designer lines and implements a .ui is implementing a designer like bunch of junk. Again if I am wrong on that so be it -- but considering how much abuse of that featurette is being propagated I would be surprised a bit if that .ui that is being referenced is not that junk in one format or another.

    So is this Qt Design Studio just an IDE that produces real gui code or does it produce black-box untouchable code as well?



  • I was just trying to create a UI (eg: button) in Qt Design Studio and was looking for a way to integrate the UI with PySide2. So should I make the UI in QML and then use it in PySide2 or is there a way to access the widgets made with Qt Design Studio in PySide2. I would really appreciate any suggestion as I am completely new to PySide2 and Qt.


  • Banned

    Okay here are two proper ways to display a button in Qt using PySide2

    This is using a Widget to properly contain a Button which would be the most python-qt-ish way to do it

    from PySide2.QtCore  import Slot
    #from PySide2.QtGui     import 
    from PySide2.QtWidgets import QApplication, QWidget, QHBoxLayout, QVBoxLayout
    from PySide2.QtWidgets import QPushButton
    
    class AppWidget(QWidget):
        def __init__(self):
            QWidget.__init__(self)
            self.setWindowTitle('Push Me')
            Top = 200; Left = 700; Wdth = 250; Hght = 100
            self.setGeometry(Left, Top, Wdth, Hght)
    
            self.btnPush = QPushButton('Push')
            self.btnPush.clicked.connect(self.Pushed)
            
            HBox = QHBoxLayout()
            HBox.addWidget(self.btnPush)
            HBox.addStretch(1)
            
            VBox = QVBoxLayout()
            VBox.addLayout(HBox)
            VBox.addStretch(1)
    
            self.setLayout(VBox)
    
        @Slot()
        def Pushed(self):
            print('Quit pushing me down.')
        
    if __name__ == '__main__':
        MainEvntHndlr = QApplication([])
    
        MainApp = AppWidget()
        MainApp.show()
    
        MainEvntHndlr.exec()
    
      # If anyone wants more extensive free help I run an online lab-like classroom-like 
      # message server feel free and drop by you will not be able to post until I clear 
      # you as a student as this prevents spammers so if interested here is the invite
      # https://discord.gg/3D8huKC
    

    Here we are just using the Button all by itself which causes the button to act quite differently from how it is designed but it works because its based on a QWidget and thus can be its own window

    from PySide2.QtCore    import Slot
    #from PySide2.QtGui     import 
    from PySide2.QtWidgets import QApplication, QPushButton
    
    class AppWidget(QPushButton):
        def __init__(self):
            QPushButton.__init__(self)
            self.setText('Push Me')
            Top = 200; Left = 700; Wdth = 100; Hght = 50
            self.setGeometry(Left, Top, Wdth, Hght)
            self.clicked.connect(self.Pushed)
    
        @Slot()
        def Pushed(self):
            print('Quit pushing me down.')
        
    if __name__ == '__main__':
        MainEvntHndlr = QApplication([])
    
        MainApp = AppWidget()
        MainApp.show()
    
        MainEvntHndlr.exec()
    

    Hopefully the above will help with your issue or at least get you on the path you need to be on to solve it yourself



  • Thanks a lot. Is there a way where we can create widgets or the UI in QtDS and use it in PySide2? I want to use Qt DS to design the UI for a desktop application.


  • Banned

    Okay I am going to assume that you can export your GUI from QtDS much like you can from the Designer but then you will still need to run a conversion (which produces garbate code) that translates it into a version of python-qt that then gets rendered.

    Still again creating something in straight PySide2 is fairly simple and easy so why do you need to complicate things and try to reinvent the wheel so-to-speak



  • Is it possible to use Material design components inside Qt Designer to create UI for a desktop application?


  • Lifetime Qt Champion

    @Denni-0 said in PySide2 with Qt Design Studio:

    Okay I am going to assume that you can export your GUI from QtDS much like you can from the Designer but then you will still need to run a conversion (which produces garbate code) that translates it into a version of python-qt that then gets rendered.

    Still again creating something in straight PySide2 is fairly simple and easy so why do you need to complicate things and try to reinvent the wheel so-to-speak

    Don't assume, these are unrelated technologies. QtDS creates QtQuick interfaces which has nothing to do with widgets.



  • @Denni-0 re - "or does it produce black-box untouchable code as well?" - It produces QML that you can edit as code if you prefer, or use the designer tooling if that's more your thing. Perhaps you should have checked this before writing your post?


  • Banned

    @BrookCronin said in PySide2 with Qt Design Studio:

    @Denni-0 re - "or does it produce black-box untouchable code as well?" - It produces QML that you can edit as code if you prefer, or use the designer tooling if that's more your thing. Perhaps you should have checked this before writing your post?

    Oooo aren't you the snarky one. Perhaps you should not have posted at all since your comment adds nothing to the original post just all negative criticism of someone who does answer questions. Heck if you actually knew more than I did you could have answered the OPs question but you did not. So all I can say is why don't you just crawl back under that useless rock you just poked your head out from under no one cares about this kind of junk.


  • Lifetime Qt Champion

    @Denni-0 said in PySide2 with Qt Design Studio:

    @BrookCronin said in PySide2 with Qt Design Studio:

    @Denni-0 re - "or does it produce black-box untouchable code as well?" - It produces QML that you can edit as code if you prefer, or use the designer tooling if that's more your thing. Perhaps you should have checked this before writing your post?

    Oooo aren't you the snarky one. Perhaps you should not have posted at all since your comment adds nothing to the original post just all negative criticism of someone who does answer questions. Heck if you actually knew more than I did you could have answered the OPs question but you did not. So all I can say is why don't you just crawl back under that useless rock you just poked your head out from under no one cares about this kind of junk.

    Please stay polite.

    It is a fact that every time the words Design/Designers appears in a Python related question, you first answer by saying that it is wrong to use that tool and that it generates crap code.

    In the case of this thread, you did not even tried to check what exactly Qt Design Studio is and what it produces. You assumed something entirely wrong while at the same time criticizing what it produces without doing any verification.

    Basically, in this thread, you are completely out of context and not helping the OP at all since he would like to run a QtQuick GUI with PySide2 and not one widget based.

    Everybody can be wrong, so let's stay civilized and constructive.


  • Banned

    Yep @SGaist and when you pointed it out politely I had no issue with that at all but BrookCronin was (1) Stating something you had already pointed out (2) Adding nothing to the OP nor adding anything that had not already been denoted at that point -- All they chose to add was a snarky comment directed at me but I do not see you saying anything about that comment. Seems like being a Troll on this forum is an okay thing and further my comment was just as polite as BrookCronin's comment.



  • Thank you @SGaist and @Denni-0 for your advice. I really appreciate it. Can we include material design components for the widgets in PySide2?


Log in to reply