Important: Please read the Qt Code of Conduct -

Qt Creator (design view) insert a class object onto the form [SOLVED]

  • Currently trying to figure out how to use the .ui form correctly. Currently what I have is a layout class which creates an object called mplayer_wrapper, currently I do all the layout in the layout constructor. However I would like to know how I would insert mplayer_wrapper onto the designer so that I can manage it there.

    Currently I am thinking that I have to use the "Widget" object on the design pane, however not sure how to implement this correctly.

    MainWindow constructor
    @ mplayer_wrapper *wrapper = new mplayer_wrapper(this);

    This is the object I wish to display on the form which I currently use by creating a vlayout in the code.


    If someone could point me to a link or how to actually create this on the ui form I would be very grateful.

  • Hii.
    Do you want to use your mplayer_wrapper class object into designer ?

  • Yea would like to set it's layout via the designer whether that be inserting it into another "pane" which I then control or control the size and position of the object itself. Either way I'll be happy just trying to implement my code in the designer instead.

    Here is the whole constructor layout class which contains all the things I would like to do on the designer instead of in code.
    @ MainWindow::MainWindow(QWidget *parent) :
    ui(new Ui::MainWindow)

    QPalette p(palette());
    p.setColor(QPalette::Background, Qt::lightGray);
    this->setWindowTitle(QApplication::translate("toplevel", "CCTV"));
    mplayer_wrapper *wrapper = new mplayer_wrapper(this);
    label = new QLabel(this);
    Timer = new QTimer(this);
    button1 = new QPushButton("Stop State");
    button2 = new QPushButton("Start Stream");
    button3 = new QPushButton("Time");
    vlayout = new QVBoxLayout();
    connect(button1, &QPushButton::clicked,wrapper,&mplayer_wrapper::stop_mplayer);
    connect(button2, &QPushButton::clicked,wrapper,&mplayer_wrapper::start_mplayer);
    //connect(button3, &QPushButton::clicked,this,   &MainWindow::show_time);


    As you can see I tried to insert wrapper into the "widget" created on the ui form (commented out at the bottom), however that is definitely the incorrect method to insert it inside but really have no clue how I should be doing it.

  • Hiii..
    it is not possible during design time ..if you want to see an object(like wrapper) on your designer and manage it using designer.
    it can be possible via code (during run time).

  • Ok if it's not possible to manipulate the actual object itself on the designer, how would I create a widget/pane on the designer and then place my object (wrapper) into this widget/pane ?

  • tell me what is your wrapper object is it any widget ?

  • Yea it inherits from a QWidget so yes.

  • Ok
    No problem ..

    then you have to take a normal QWidget having the geometry like wrapper on widget/pane Window .then replace it via coding.

    NOTE:The best way to do so by coding its provides flexibility.

  • Not actually asking to actually replace a widget that is on the form with one that is in my code. All I want to do is insert my QWidget object inside an Widget created on the form so that I can set the design.

    Anyway what your saying doesn't really help me, as all you have told me is what to do rather than how to do it. Anything will do just need a link to a useful post on it as I know it can be done just no idea how to do it.

  • Ah well figure a way I can do it making as solved.

  • Lifetime Qt Champion


    If I've understood you correctly it looks like the "Creating Custom Widgets for Qt Designer" chapter of Qt's documentation is the place to start

  • Hey SGaist,

    Gave them a go they work ok but it just doesn't seem right for my application. As all I am wanting to do is create widgets (multiples) inside another widget (which is on the form) so that I can set a fix layout for the widget (the one on the form), so the internal widgets (no matter how many there are) will always keep to the size of "widget".

    Also what are the overheads in using a custom widget ? Disadvantages etc ?

Log in to reply