Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to encapsulate ui form inside another



  • Hello!

    I'm slowly developing the application in Qt in linux environment, it's some kind of port from things I've done in .net environment so I have habits I can't get over.

    The primary thing I'm looking for is how may I achieve form & controls encapsulation; in .net I used to (simple example):

    1. Create mainform (qmainwindow equivalent), put some basic widgets around, dock elements, containers.
    2. Create another form (qmainwindow/qwidget), place controls, build internal logic and behaviors.
    3. Drag 'another' form onto 'mainform' inside the designer, align, dock, done; I could play in separeted environments via events, whatever :)

    Well, I jumped from tutorials to docs and still I can't find some reasonable way to achieve the same thing. The closest part is custom widget done via plugin, but there is so much overhead that i'd rather reconsider that approach.

    I'll be happy to hear some hints which topics I should hit to solve my issue, or at least some general brief.


  • Lifetime Qt Champion



  • I used to promote classes to extend some basic widgets, today I've tried to extend widget and promote QWidget to my form class and I failed, looks like I've done something wrong because it didn't load controls from another .ui. I've seen an example with custom paint method which worked, so I'll give it a try one more time :)



  • @Pepas Hi,
    I used to promote classes to do this and it normally works well, and they normally inherit by QWidget .
    Anyway I did a quick test and here you find result:

    • I Tried to promote a QWidget that exist in my UI in UI that inherits by QDialog : it didn’t work
    • I Tried to promote a QWidget that exist in my UI in UI that inherits by QWidget: it did work well

    Is it possible you are in same first condition?

    How kind of superclass is your UI to promote?

    PS: sorry for my English



  • Ok, solved that issue. I've made an error, I can promote mainwindow.ui 'dropped' widget to another widget class and controls are loading properly :) The only flaw it has is that promoted widged isn't visible in mainwindow.ui.


Log in to reply