Accessing elements of the child user interface in the Qt interface

I defined a UI (let me have myUI) to use the Qt constructor and use it in my applications. I need to access all sub-widgets ( QToolButtons) in myUI. I want to get all the subspecies as QObjectList.

Is there any way to do this?

QObject::children()does not work here because the Qt UI compiler, when converting a .ui file to a C ++ class, does not define the ui_myUI class as a subclass of any derived class QObject. Is there a way to get this to do this and then use the function children()?

Thank.

+3
source share
4 answers

Call children()in the instance of the top-level widget.

, "tlWidget":

myUI->tlWidget->children()

+4

, UI, , setupUi, this . Qt Creator/Designer , ui.
, .

+1
0

?

(a) - :

class MyWidget: public QWidget, protected myUI 
{
//...
};

(b) , , - :

class MyWidget: public QWidget
{
protected:
    myUI ui;
};

, , setupUi(this) ui.setupUi(this) MyWidget

setupUi (QWidget * p) QWidget p, , children() p:

this->children(); //"this" refers to an object of MyWidget
0

Source: https://habr.com/ru/post/1726339/


All Articles