UIC output generates a Qt UI class from the user interface

I have a simple Qt question. I want the automatically generated UIC files to be retrieved from the user interface class, for example:

Intention

class MyUiInterface {
public:
     virtual void setupUi(QWidget* w) = 0;
     virtual void retranslateUi(QWidget*w) = 0;
};

The generated UIC file should look like this:

class Ui_MyWidget {
public:
    void setupUi(QWidget* w) {
        ...
    }
    void retranslateUi(QWidget* w) {
        ...
    }
};

namespace Ui {
    class MyWidget : public MyUiInterface , public Ui_MyWidget {};
}

Why?

Each Ui :: Class will implement MyUiInterface. In every class that comes from Ui :: Class (see Multiple Inheritance Method ), I could call setupUiand retranslateUi, which makes sense, if the class that comes from UI :: The class of the class is also a base class. I want each widget to be derived from my abstrcat base class MyWidgetBase. Consider the following:

class MyWidgetBase abstract : public QWidget, protected MyUiInterface {
protected:
    void changeEvent(QEvent *e) {
        QWidget::changeEvent(e);
        if (e->type() == QEvent::LanguageChange) {
            retranslateUi(this); // Still abstract here
        }
    }
};

class MyWidget : public MyWidgetBase : public Ui::MyWidget {
};

, , MyWidget:: changeEvent(), retranslateUi . changeEvent . " ".

, Qt UIC , ? ?

+5
1

, XML Schema ui , uic .

, - UIC - , , .h, , xml , ++.

setupUi retranslateUi MyWidget? Ui , . , - , .

class MyWidget : public MyWidgetBase, public Ui::MyWidget {
public:
    void setupUi(QWidget* w) {
        ...
    }
    void retranslateUi(QWidget* w) {
        ...
    }

};

changeEvent() , changeEvent retranslateUi().

0
source

All Articles