Reuse Qt UI class [SOLVED]
-
I have files user.cpp user.h user.ui, this class is used show then user's details on application. now i want to extend this class to employee. employee class have password reset fuction additionally. In employe ui file it must have textfield for password. all other are same as user class. now i want to use user.ui form to create employee.ui form. just want to add some textfield additionally.
-
Hi and welcome to devnet,
In general you can reuse ui files in other classes; if you paste some code we could help you in a better way
-
There is no inheritance of UI xml files, and the generated form classes in the Ui:: namespace reflect this.
A few approaches:
- Build a single form containing everything for the employee case and use that UI in both C++ classes. In the UserForm class setup the UI and hide the Employee extra widgets, and in the EmployeeForm set up the UI and just use the form as-is.
- Build a single form containing everything for the employee case and use that UI in a single C++ class that can be constructed in two modes. In one mode hide the extra widgets.
- Build a single form containing only the UserForm widgets. Use that form in both classes but in the EmployeeForm class programmtically add more widgets to the UI.
-
There is no inheritance of UI xml files, and the generated form classes in the Ui:: namespace reflect this.
A few approaches:
- Build a single form containing everything for the employee case and use that UI in both C++ classes. In the UserForm class setup the UI and hide the Employee extra widgets, and in the EmployeeForm set up the UI and just use the form as-is.
- Build a single form containing everything for the employee case and use that UI in a single C++ class that can be constructed in two modes. In one mode hide the extra widgets.
- Build a single form containing only the UserForm widgets. Use that form in both classes but in the EmployeeForm class programmtically add more widgets to the UI.
-
There is no inheritance of UI xml files, and the generated form classes in the Ui:: namespace reflect this.
A few approaches:
- Build a single form containing everything for the employee case and use that UI in both C++ classes. In the UserForm class setup the UI and hide the Employee extra widgets, and in the EmployeeForm set up the UI and just use the form as-is.
- Build a single form containing everything for the employee case and use that UI in a single C++ class that can be constructed in two modes. In one mode hide the extra widgets.
- Build a single form containing only the UserForm widgets. Use that form in both classes but in the EmployeeForm class programmtically add more widgets to the UI.