Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to pass a parameter to a widget created by designer
QtWS25 Last Chance

How to pass a parameter to a widget created by designer

Scheduled Pinned Locked Moved General and Desktop
10 Posts 5 Posters 9.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    UneHuitre
    wrote on last edited by
    #1

    Hi everyone!

    I'm currently working on a project where I need to integrate an OpenGL widget to a window. Hence I've created an UI with the designer where I've put my widget, inheriting the QGLWidget class. The default constructor, generated after editing the window on Qt designer, only takes the parent widget as a parameter for construction. Thus I would like to also pass the format to the widget constructor but it is a non constant parameter that I need to initialize before calling the constructor, and yet the constructor is automatically called when setting up the UI.

    Does anyone know how I can give the format once set during initialization to the constructor called by UI init?

    Thanks a lot!
    UneHuitre

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mcosta
      wrote on last edited by
      #2

      Hi,

      there's a way to pass this parameter via a set method? or it's mandatory to pass in contructor??

      Once your problem is solved don't forget to:

      • Mark the thread as SOLVED using the Topic Tool menu
      • Vote up the answer(s) that helped you to solve the issue

      You can embed images using (http://imgur.com/) or (http://postimage.org/)

      1 Reply Last reply
      0
      • U Offline
        U Offline
        UneHuitre
        wrote on last edited by
        #3

        Hi mcosta!

        Actually the setFormat method is deprecated, I tried to call it from my widget constructor but it either generates a segfault (when trying to set the format to OpenGL 3.3) or doesn't change anything since the value of GL_VERSION is the same as when the widget format is not set.

        So I guess the only way is to give my format to the constructor!

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Adrien Leravat
          wrote on last edited by
          #4

          Hi,

          I think the only option is to create it at runtime manually, instead of using directly code generated from your UI. You may copy code directly from your compiled file myForm_ui.h, and modify it to your needs. You can indeed integrate this code into a form-based widget class.

          If you really want to stick with QtDesigner, you can create a wrapper widget, with a setter for your parameter, delaying the OpenGL widget or rebuilding it from inside your widget. It can then be used in Designer using the right click "Promote to...", or by creating a plugin for your widget, to integrate it to Designer.

          But I do recommand the first solution, which is much easier !

          Adeneo Embedded - www.adeneo-embedded.com

          1 Reply Last reply
          0
          • U Offline
            U Offline
            UneHuitre
            wrote on last edited by
            #5

            Salut Adrien (plus simple en français!)

            Je vais essayer ça de suite, merci beaucoup pour ta réponse!

            1 Reply Last reply
            0
            • A Offline
              A Offline
              Adrien Leravat
              wrote on last edited by
              #6

              Pas de quoi, tiens nous au courant :)

              Adeneo Embedded - www.adeneo-embedded.com

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maximus
                wrote on last edited by
                #7

                Salut,

                Il n'y a pas vraiment de moyen de le passer d'autres arguments dans le constructeur si tu utilises designer, je te conseilles d'utiliser une methode publique dans ton objet et le faire en deux temps.

                -Initialisation
                -passer paramètres (fonction publique)

                Bonne chance!


                Free Indoor Cycling Software - https://maximumtrainer.com

                1 Reply Last reply
                0
                • U Offline
                  U Offline
                  UneHuitre
                  wrote on last edited by
                  #8

                  Well Adrien's advice did the trick!

                  I used the compiled myWindow_ui.h to get the existing code and integrated it directly in my MainWindow constructor, actually I was sure I would have many issues by doing it both by scripting and by using designer, whereas it happened to be quite easy!

                  All I had to do was to rewrite my widget constructor to pass the format argument, call it in the constructor and manually integrate my widget to the layout created with designer.

                  Thanks a lot everyone!

                  1 Reply Last reply
                  0
                  • A Offline
                    A Offline
                    Adrien Leravat
                    wrote on last edited by
                    #9

                    Glad it helped :)
                    Happy coding with Qt !

                    Adeneo Embedded - www.adeneo-embedded.com

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #10

                      Hi guys,

                      Please keep the language of the threads in english, it's the official language for the forum except the regional forums. You can always ask our forum chief to create one for french.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved