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. Is there way to use QT Designer UI forms so you get direct access to the form widgets in your program?
QtWS25 Last Chance

Is there way to use QT Designer UI forms so you get direct access to the form widgets in your program?

Scheduled Pinned Locked Moved Unsolved General and Desktop
16 Posts 3 Posters 3.6k 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.
  • SGaistS Offline
    SGaistS Offline
    SGaist
    Lifetime Qt Champion
    wrote on last edited by
    #4

    That's why I asked about the backend implementation ;)

    Your widgets should be responsible for connecting to the backend so one way to do that is to add a setupBackend method to them and in there do all the connection needed. Doing so you have access directly to said widget internal details thus if you modify it, you only have to change code within that widget. This keeps your code clean and easy to maintain.

    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
    • C Offline
      C Offline
      Crag_Hack
      wrote on last edited by
      #5

      You're talking about my form top level widgets right? So I just add the method to the form class? How do I connect signals and slots between the form and the backend then? Also curious about your mention of the possibility of direct access in the first reply - can you elaborate a little?
      Thanks again

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

        I mean any widgets you build that would need a connection to your backend.

        You do the connections in that method i.e.:

        void MyCoolWidget::setupBackend(MyCoolBackend *backend)
        {
            connect(backend, &MyCoolBackend::stringBasedSignal, ui->statusLabel, &QLabel::setText);
            // etc.
        }
        

        That way all the code stays in MyCoolWidget and if you change that class e.g. you replace the QLabel by a QLineEdit, you only have to modify setupBackend. No need to hunt every line where you could have done a connection between MyCoolWidget and MyCoolBackend.

        You can give access to the ui variable from your widgets. Again, I very strongly advice to not do such a thing.

        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
        • C Offline
          C Offline
          Crag_Hack
          wrote on last edited by
          #7

          What if I have to go the other way around? - click a button on a widget and do some backend stuff. Also as you probably figured out I'm a newbie to all this stuff. I have a background in data structures and basic programming and inheritance etc... - I'm basically an intermediate level programmer. Can you recommend any books or tutorials to help me out with this scenario of backend vs fronted and ui forms specifcally QT? Thanks :)

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

            Same principle:

            void MyCoolWidget::setupBackend(MyCoolBackend *backend)
            {
                connect(backend, &MyCoolBackend::stringBasedSignal, ui->statusLabel, &QLabel::setText);
                connect(ui->startButton, &QPushButton::clicked, backend, &MyCoolBackend::igniteToaster);
                // etc.
            }
            

            This book might be of interest. Look for the parts about the Façade pattern.

            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
            1
            • C Offline
              C Offline
              Crag_Hack
              wrote on last edited by
              #9

              If I were to read one QT book... which would you suggest? :) The same? Perhaps just the Facade pattern then another book? I'll stop bugging you now ...

              mrjjM 1 Reply Last reply
              0
              • C Crag_Hack

                If I were to read one QT book... which would you suggest? :) The same? Perhaps just the Facade pattern then another book? I'll stop bugging you now ...

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @Crag_Hack
                Hi
                When i started with Qt, i like to browse around in this one
                http://www.bogotobogo.com/cplusplus/files/c-gui-programming-with-qt-4-2ndedition.pdf
                I find it goes well with Qt docs to learn about different classes and ways to structure the app.

                1 Reply Last reply
                0
                • C Offline
                  C Offline
                  Crag_Hack
                  wrote on last edited by
                  #11

                  Do either of those books cover how to make graphical renditions of widgets like special cool looking buttons and windows etc? Thanks. That's all folks!

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

                    What kind of special cool looking buttons do you have in mind ?

                    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
                    • C Offline
                      C Offline
                      Crag_Hack
                      wrote on last edited by
                      #13

                      These are a good example... just general graphic design for guis.
                      samsung ssd magician
                      mozy

                      1 Reply Last reply
                      0
                      • C Offline
                        C Offline
                        Crag_Hack
                        wrote on last edited by
                        #14

                        It does appear deceptively complicated to me initially but upon second look actually looks kinda simple :) toughest part being developing an eye for such things

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

                          For the first one I'd recommend going with QtQuick, that will be easier to build. The second can be accomplished with widgets with some styling but again, you'll likely be faster with QtQuick to do it.

                          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
                          • C Offline
                            C Offline
                            Crag_Hack
                            wrote on last edited by Crag_Hack
                            #16

                            I'd rather not use QT Quick unless it's necessary because I'm not familiar with it. Maybe I should bite the bullet and learn it... With widgets though do those books teach you how to do gradients / style sheets / icons and graphics etc so you can make great looking programs? Also if QT Quick is super easier and more effective can I integrate with my C++ backend?

                            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