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 get Widget from UI file
Forum Updated to NodeBB v4.3 + New Features

How to get Widget from UI file

Scheduled Pinned Locked Moved Unsolved General and Desktop
19 Posts 5 Posters 2.2k Views 2 Watching
  • 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 20 Jun 2022, 12:07 last edited by
    #1

    I have an existing TabWidget in a UI file, I want to get QWidget tabs from the file so I can manipulate them and add them to other classes.

    Can I use findChild passing the objectName assigned in the UI file ?

    Kind Regards,
    Sy

    J 1 Reply Last reply 20 Jun 2022, 12:09
    0
    • S SPlatten
      20 Jun 2022, 12:07

      I have an existing TabWidget in a UI file, I want to get QWidget tabs from the file so I can manipulate them and add them to other classes.

      Can I use findChild passing the objectName assigned in the UI file ?

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 20 Jun 2022, 12:09 last edited by
      #2

      @SPlatten I don't understand the question. Everything from UI file is accessed using ui->objectName
      What does "so I can manipulate them and add them to other classes" mean?

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      S 1 Reply Last reply 20 Jun 2022, 12:11
      0
      • J jsulm
        20 Jun 2022, 12:09

        @SPlatten I don't understand the question. Everything from UI file is accessed using ui->objectName
        What does "so I can manipulate them and add them to other classes" mean?

        S Offline
        S Offline
        SPlatten
        wrote on 20 Jun 2022, 12:11 last edited by SPlatten
        #3

        @jsulm , I'm trying to implement a more elegant solution where the name and pointer return can be changed for validity. I will try your suggestion first.

        [Edit] The class TabWidget needs to get the tabs, how can I access the enclosing UI document from the TabWidget constructor ?

        Kind Regards,
        Sy

        J 1 Reply Last reply 20 Jun 2022, 13:00
        0
        • S SPlatten
          20 Jun 2022, 12:11

          @jsulm , I'm trying to implement a more elegant solution where the name and pointer return can be changed for validity. I will try your suggestion first.

          [Edit] The class TabWidget needs to get the tabs, how can I access the enclosing UI document from the TabWidget constructor ?

          J Online
          J Online
          JonB
          wrote on 20 Jun 2022, 13:00 last edited by
          #4

          @SPlatten
          I'm not sure you can/I understand what you want. Whatever, the answer lies in looking in tabwidget.h and/or ui_tabwidget.h since those are the entire code.

          S 1 Reply Last reply 20 Jun 2022, 13:03
          0
          • J JonB
            20 Jun 2022, 13:00

            @SPlatten
            I'm not sure you can/I understand what you want. Whatever, the answer lies in looking in tabwidget.h and/or ui_tabwidget.h since those are the entire code.

            S Offline
            S Offline
            SPlatten
            wrote on 20 Jun 2022, 13:03 last edited by
            #5

            @JonB , I'm just trying to meet a request, which something shown in the tab is in a fault state the tab itself should be shown in a red background. The existing UI has the tabs and controls, but I cannot get this to work with the existing tabs in the UI, if I create the tabs from scratch it works.

            Kind Regards,
            Sy

            J 1 Reply Last reply 20 Jun 2022, 13:09
            0
            • S SPlatten
              20 Jun 2022, 13:03

              @JonB , I'm just trying to meet a request, which something shown in the tab is in a fault state the tab itself should be shown in a red background. The existing UI has the tabs and controls, but I cannot get this to work with the existing tabs in the UI, if I create the tabs from scratch it works.

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 20 Jun 2022, 13:09 last edited by J.Hilk
              #6

              @SPlatten have you considered checking the auto generated "ui_class.h"file and simply taking the c++ code of your tabs from there and than using that code to create them yourself?


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              S 2 Replies Last reply 20 Jun 2022, 13:10
              0
              • J J.Hilk
                20 Jun 2022, 13:09

                @SPlatten have you considered checking the auto generated "ui_class.h"file and simply taking the c++ code of your tabs from there and than using that code to create them yourself?

                S Offline
                S Offline
                SPlatten
                wrote on 20 Jun 2022, 13:10 last edited by
                #7

                @J-Hilk , will take a look now.

                Kind Regards,
                Sy

                1 Reply Last reply
                0
                • J J.Hilk
                  20 Jun 2022, 13:09

                  @SPlatten have you considered checking the auto generated "ui_class.h"file and simply taking the c++ code of your tabs from there and than using that code to create them yourself?

                  S Offline
                  S Offline
                  SPlatten
                  wrote on 20 Jun 2022, 13:13 last edited by
                  #8

                  @J-Hilk , looking at the header ui_ws_status_page.h, this contains the class Ui_WsStatusPage which does have everything I need, however I've just searched the file system for Ui_WsStatusPage and there are no references to it, how to I use it?

                  Kind Regards,
                  Sy

                  J 1 Reply Last reply 20 Jun 2022, 13:16
                  0
                  • S SPlatten
                    20 Jun 2022, 13:13

                    @J-Hilk , looking at the header ui_ws_status_page.h, this contains the class Ui_WsStatusPage which does have everything I need, however I've just searched the file system for Ui_WsStatusPage and there are no references to it, how to I use it?

                    J Online
                    J Online
                    JonB
                    wrote on 20 Jun 2022, 13:16 last edited by
                    #9

                    @SPlatten
                    Please just look (carefully) at the code. I said before

                    Whatever, the answer lies in looking in tabwidget.h and/or ui_tabwidget.h since those are the entire code.

                    If you don't follow put in breakpoints and step through, there is no magic and nothing external here.

                    S 1 Reply Last reply 20 Jun 2022, 13:18
                    0
                    • J JonB
                      20 Jun 2022, 13:16

                      @SPlatten
                      Please just look (carefully) at the code. I said before

                      Whatever, the answer lies in looking in tabwidget.h and/or ui_tabwidget.h since those are the entire code.

                      If you don't follow put in breakpoints and step through, there is no magic and nothing external here.

                      S Offline
                      S Offline
                      SPlatten
                      wrote on 20 Jun 2022, 13:18 last edited by
                      #10

                      @JonB , looking at the class as I said it does contain everything I need but I cannot find Ui_WsStatusPage (Class name) anywhere else in the file system or source code except in the header file itself.

                      Kind Regards,
                      Sy

                      J 1 Reply Last reply 20 Jun 2022, 13:19
                      0
                      • S SPlatten
                        20 Jun 2022, 13:18

                        @JonB , looking at the class as I said it does contain everything I need but I cannot find Ui_WsStatusPage (Class name) anywhere else in the file system or source code except in the header file itself.

                        J Online
                        J Online
                        JonB
                        wrote on 20 Jun 2022, 13:19 last edited by JonB
                        #11

                        @SPlatten
                        So put a breakpoint on its constructor, and on setupUi()..... If you are right, they will never be called and you can ignore all their code.

                        S 1 Reply Last reply 20 Jun 2022, 13:20
                        0
                        • J JonB
                          20 Jun 2022, 13:19

                          @SPlatten
                          So put a breakpoint on its constructor, and on setupUi()..... If you are right, they will never be called and you can ignore all their code.

                          S Offline
                          S Offline
                          SPlatten
                          wrote on 20 Jun 2022, 13:20 last edited by
                          #12

                          @JonB said in How to get Widget from UI file:

                          I wish I could, but the project is built with cmake, not in Qt Creator, I can only run it in the console.

                          Kind Regards,
                          Sy

                          J J 2 Replies Last reply 20 Jun 2022, 13:21
                          0
                          • S SPlatten
                            20 Jun 2022, 13:20

                            @JonB said in How to get Widget from UI file:

                            I wish I could, but the project is built with cmake, not in Qt Creator, I can only run it in the console.

                            J Offline
                            J Offline
                            JKSH
                            Moderators
                            wrote on 20 Jun 2022, 13:21 last edited by
                            #13

                            @SPlatten said in How to get Widget from UI file:

                            I wish I could, but the project is built with cmake, not in Qt Creator, I can only run it in the console.

                            You can use Qt Creator to open a CMakeLists.txt project and run console applications.

                            Qt Doc Search for browsers: forum.qt.io/topic/35616/web-browser-extension-for-improved-doc-searches

                            1 Reply Last reply
                            1
                            • S SPlatten
                              20 Jun 2022, 13:20

                              @JonB said in How to get Widget from UI file:

                              I wish I could, but the project is built with cmake, not in Qt Creator, I can only run it in the console.

                              J Online
                              J Online
                              JonB
                              wrote on 20 Jun 2022, 13:23 last edited by
                              #14

                              @SPlatten
                              Then edit the code to put in a qDebug(), or a message box, or a print to file, or whatever....

                              Or, comment out that class, since you have said it is never used, and recompile.

                              S 1 Reply Last reply 20 Jun 2022, 13:28
                              0
                              • J JonB
                                20 Jun 2022, 13:23

                                @SPlatten
                                Then edit the code to put in a qDebug(), or a message box, or a print to file, or whatever....

                                Or, comment out that class, since you have said it is never used, and recompile.

                                S Offline
                                S Offline
                                SPlatten
                                wrote on 20 Jun 2022, 13:28 last edited by
                                #15

                                @JonB , can I edit the content of ui_ws_status_page.h and add to it?

                                Kind Regards,
                                Sy

                                J 1 Reply Last reply 20 Jun 2022, 13:30
                                0
                                • S SPlatten
                                  20 Jun 2022, 13:28

                                  @JonB , can I edit the content of ui_ws_status_page.h and add to it?

                                  J Offline
                                  J Offline
                                  jsulm
                                  Lifetime Qt Champion
                                  wrote on 20 Jun 2022, 13:30 last edited by
                                  #16

                                  @SPlatten Your changes will be overridden next time this header file is generated

                                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                                  S 1 Reply Last reply 20 Jun 2022, 13:32
                                  1
                                  • J jsulm
                                    20 Jun 2022, 13:30

                                    @SPlatten Your changes will be overridden next time this header file is generated

                                    S Offline
                                    S Offline
                                    SPlatten
                                    wrote on 20 Jun 2022, 13:32 last edited by
                                    #17

                                    @jsulm , ok, so how can I fix the tabs in the UI to do what I want? I'm done this without the tabs in the UI but its to be a job to rip it all apart. Right now I need to call setTabBar after all the initialisation has completed with the tabs added, but I cannot all setTTabBar outside of the class as its a protected method.

                                    Kind Regards,
                                    Sy

                                    J 1 Reply Last reply 20 Jun 2022, 13:39
                                    0
                                    • S SPlatten
                                      20 Jun 2022, 13:32

                                      @jsulm , ok, so how can I fix the tabs in the UI to do what I want? I'm done this without the tabs in the UI but its to be a job to rip it all apart. Right now I need to call setTabBar after all the initialisation has completed with the tabs added, but I cannot all setTTabBar outside of the class as its a protected method.

                                      J Online
                                      J Online
                                      JonB
                                      wrote on 20 Jun 2022, 13:39 last edited by
                                      #18

                                      @SPlatten
                                      Outside of what class? I really don't know your code. If you need to access a protected method then subclass and you can do what you like?

                                      S 1 Reply Last reply 20 Jun 2022, 13:41
                                      0
                                      • J JonB
                                        20 Jun 2022, 13:39

                                        @SPlatten
                                        Outside of what class? I really don't know your code. If you need to access a protected method then subclass and you can do what you like?

                                        S Offline
                                        S Offline
                                        SPlatten
                                        wrote on 20 Jun 2022, 13:41 last edited by
                                        #19

                                        @JonB , its really not my code, I'm just trying to make it work and failing.

                                        Kind Regards,
                                        Sy

                                        1 Reply Last reply
                                        0

                                        8/19

                                        20 Jun 2022, 13:13

                                        • Login

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