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. Can I use my widgets created with code in the *.ui file
QtWS25 Last Chance

Can I use my widgets created with code in the *.ui file

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 2 Posters 1.4k 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.
  • R Offline
    R Offline
    roseicollis
    wrote on last edited by
    #1

    Hi everybody!
    I have a project in Qt made with the QWizard and QWizardPage classes. There are two ways to create a widget i.e: a Label:

    One is going to the *.ui file and search the element and put it where you want (visual way). Then you can access it on your code with

    ui->nameOfLabel.
    

    The other one is going to your code and creating it like

    QLabel codedLabel;
    

    Actually I'm using the second way (it's easier for me to create, show and use) but my question is: Is there any way that I can see my label codedLabel on the *.ui file?

    I would like to move it to a space in the screen and in that case, it would be much easier for me to be able to do it through the visual way (but having the label created in the code instead of the ui).

    Thank you so much.

    1 Reply Last reply
    0
    • kshegunovK Offline
      kshegunovK Offline
      kshegunov
      Moderators
      wrote on last edited by kshegunov
      #2

      Hello,
      I'm pretty sure this is not possible. A form (the *.ui files) is just an XML definition that is translated by the uic (user interface compiler) into a C++ class. That being said, uic knows nothing of your code or what object you create, it just provides you with the class corresponding to the form.

      Kind regards.

      Read and abide by the Qt Code of Conduct

      R 1 Reply Last reply
      0
      • kshegunovK kshegunov

        Hello,
        I'm pretty sure this is not possible. A form (the *.ui files) is just an XML definition that is translated by the uic (user interface compiler) into a C++ class. That being said, uic knows nothing of your code or what object you create, it just provides you with the class corresponding to the form.

        Kind regards.

        R Offline
        R Offline
        roseicollis
        wrote on last edited by
        #3

        @kshegunov Thanks for your reply. That's what I was afraid of... but thought that maybe there was a way that I didn't saw.

        Then... let me ask you another thing... I have a really big project with aprox 40 QWizardPage class forms (like a c++ class but with a *.ui file for each one). I used that class because I started learning Qt with no idea and a mate thought this would be the best class cause I could use the visual ui... but not. So my question is: can I delete now all that *.ui files and still be able to run my program? (Of course I have already commented every mention to a *.ui in the code).

        Thanks!

        1 Reply Last reply
        0
        • kshegunovK Offline
          kshegunovK Offline
          kshegunov
          Moderators
          wrote on last edited by
          #4

          Provided you never use the classes generated by the uic (these in the Ui namespace), then the answer is yes. Forms are optional, I do prefer them, but if you don't Qt will not stop you from creating your widgets and layouts in the source code.

          Read and abide by the Qt Code of Conduct

          R 1 Reply Last reply
          0
          • kshegunovK kshegunov

            Provided you never use the classes generated by the uic (these in the Ui namespace), then the answer is yes. Forms are optional, I do prefer them, but if you don't Qt will not stop you from creating your widgets and layouts in the source code.

            R Offline
            R Offline
            roseicollis
            wrote on last edited by
            #5

            @kshegunov why do you prefer using the ui files? I mean... a part from the easy "plug and play" way, is it better for the program like more optimized or somethhing like this...

            As I don't use them, I would like to delete them to try and make the executable weight less.

            1 Reply Last reply
            0
            • kshegunovK Offline
              kshegunovK Offline
              kshegunov
              Moderators
              wrote on last edited by
              #6

              I prefer them because it spares me writing a lot of code for positioning, layout, margins, borders and the like. They certainly are not more optimized than handwritten code, but the class the uic generates is practically the same as I would have done it. All in all, the weight of using forms, is not more than doing it by hand, but it does spare you a lot of headaches (most of the time).

              Read and abide by the Qt Code of Conduct

              R 1 Reply Last reply
              0
              • kshegunovK kshegunov

                I prefer them because it spares me writing a lot of code for positioning, layout, margins, borders and the like. They certainly are not more optimized than handwritten code, but the class the uic generates is practically the same as I would have done it. All in all, the weight of using forms, is not more than doing it by hand, but it does spare you a lot of headaches (most of the time).

                R Offline
                R Offline
                roseicollis
                wrote on last edited by
                #7

                @kshegunov I see your point and yes maybe it "weights" the same (dunno the english word in that case sorry) but now I have both: the code and the empty uis so why keep them both? That's my point of deleting the uis :)

                kshegunovK 1 Reply Last reply
                0
                • R roseicollis

                  @kshegunov I see your point and yes maybe it "weights" the same (dunno the english word in that case sorry) but now I have both: the code and the empty uis so why keep them both? That's my point of deleting the uis :)

                  kshegunovK Offline
                  kshegunovK Offline
                  kshegunov
                  Moderators
                  wrote on last edited by
                  #8

                  @roseicollis
                  You probably don't need them both, since you've decided to do the coding yourself. It is, as I said, optional to use forms.

                  Read and abide by the 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