QTabWidget : how to get widget ui made with designer
-
usually i create stand alone widget with designer and the inserting it to Qtabwidget with code
this time i did the all thing with designer ,so i dont the internal widget class.
but i want to get its properties. how can i do it?
i know i can use the metaobject getchild method, but i will have to do it for each button/lineedit
how should it work? is it possible to design those widgets within the QtabWidget in the designer and still control them ?
-
usually i create stand alone widget with designer and the inserting it to Qtabwidget with code
this time i did the all thing with designer ,so i dont the internal widget class.
but i want to get its properties. how can i do it?
i know i can use the metaobject getchild method, but i will have to do it for each button/lineedit
how should it work? is it possible to design those widgets within the QtabWidget in the designer and still control them ?
@orio said in QTabWidget : how to get widget ui made with designer:
this time i did the all thing with designer ,so i dont the internal widget class.
but i want to get its properties. how can i do it?What do you mean? What internal widget class? You can easilly access all your widgets implemented in designer using ui->widgetName.
-
@jsulm said in QTabWidget : how to get widget ui made with designer:
ui->widgetName
ui->widgetName is the QTabWidget, it has widgets inside it.
i can get Widget * to them .say one of this widgets has QPushButton named pushButton_
how can i get it
This post is deleted! -
@jsulm said in QTabWidget : how to get widget ui made with designer:
ui->widgetName
ui->widgetName is the QTabWidget, it has widgets inside it.
i can get Widget * to them .say one of this widgets has QPushButton named pushButton_
how can i get it
@orio said in QTabWidget : how to get widget ui made with designer:
how can i get it
-
@orio said in QTabWidget : how to get widget ui made with designer:
how can i get it
-
so as i stated in my post , meta object find child is the only option.
now i need to find child for each inner button / lineedit and save a pointer to it .
it was bad idea to design those widgets in designer@orio But why do you need access to these sub-widgets outside of the container widget? It is bad design to make internal details known to outside world. What you can do instead: add signals to the container widget which are emitted when sub-widgets trigger some actions and connect to these signals where you need to. This way other parts of your application do not need to know anything about ui details in other widgets.
For example: connect clicked() signal from ui->pushButton_ to a signal in the widget which contains this button, so other parts of your app will connect to that signal instead of having to know about sub-widgets to connect to. -
@orio
Hi. Not 100% on what you are saying, but to answer simply.If, for whatever reason, you do not have access to direct variables referencing your widgets (the
ui->....
stuff you would end up after runninguic
on the Designer's.ui
file), then all you have isQObject::findChild<>()
andQObject::findChildren<>()
, run from whichever widget ancestor you want to descend from (top-level at least to start with). WithfindChlidren<>()
you can enumerate all widgets, so for example you can get at " each inner button / lineedit and save a pointer to it " in one go. -
@orio said in QTabWidget : how to get widget ui made with designer:
but i dont have accses to ui... again
Of course you have - in the widget where the sub widgets are.
If you create a widget in QtDesigner and put some widgets (like buttons) on it then you can access those sub widgets via ui->objectName... -
I guess there are two different ways of combining the widgets inside the QTabWidget. Let's get it sorted out, which you are using. Nevertheless, for both ways there have been the correct answers already.
-
You just have a single ui file for everything. I.e. in your ui file you have the QTabWidget, but also the subwidgets. In this case, as already mentioned, you can just access the buttons, etc. directly through ui->objectName.
-
You have one ui file for the QTabWidget and one ui file for each subwidget. Somehow (I have never tried that) inside the Designer you put the ui files of the subwidgets into the QTabWidget. @jsulm already suggested that you connect the signal of the button to the widget itself. There is a way directly inside the designer to do just that. So, inside the ui file of the subwidget you do all the connections and have a bunch of new signals in your subwidget. You'll be able to access these from your C++ code then.
-