How to get Widget from UI file
-
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 ?
-
@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?@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 ?
-
@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 ?
-
@SPlatten
I'm not sure you can/I understand what you want. Whatever, the answer lies in looking intabwidget.h
and/orui_tabwidget.h
since those are the entire code.@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.
-
@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.
-
@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?
-
@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?
-
@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?
@SPlatten
Please just look (carefully) at the code. I said beforeWhatever, the answer lies in looking in
tabwidget.h
and/orui_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.
-
@SPlatten
Please just look (carefully) at the code. I said beforeWhatever, the answer lies in looking in
tabwidget.h
and/orui_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.
-
@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.
-
@SPlatten
So put a breakpoint on its constructor, and onsetupUi()
..... If you are right, they will never be called and you can ignore all their code. -
@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.
@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.
-
@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.
-
@SPlatten
Then edit the code to put in aqDebug()
, 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.
-
@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.
-
@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.
-
@SPlatten
Outside of what class? I really don't know your code. If you need to access aprotected
method then subclass and you can do what you like?