Important: Please read the Qt Code of Conduct -

Inserting the widget in the mainwindow

  • Hi,
    I would like to ask what is the best way to display my own widget in mainwindow which I created using Qt Designer form class. I would like to make a table of such widgets with the possibility of dynamic insertion and deletion. If there were any ready examples in Qt I would be grateful for the link :)

  • Lifetime Qt Champion

    Hi and welcome to the forums
    One way is the promotion feature which i love.

    say you made the Widget called MyWidget and it lives in mywidget.h and .cpp

    Then on the MainWindow
    add a plain QWidget
    Then right click it and select Promote
    give it the class name (MyWidget) and the .h file. (mywidget.h)
    then presss Add button, then promote button.

    and then when you run its your widget :)

    also from code using ui->widgetname

    When one is promoted, you can copy & paste to get more.

    However, are you sure bulding a table of widgets is the way to go ? It will be heavy if many.
    Qt has views such as table etc for such tables / lists. if it is.

Log in to reply