setCentralWidget() for an arbitrary widget

  • Hi all.
    I am newbie. I have a stupid question for example.

    In Qt is an example for the serial port (C:\Qt\Qt5.2.0\5.2.0\mingw48_32\examples\serialport\terminal\
    In file mainwindow.cpp there is a line:

    60          setCentralWidget(console);

    This sets the console in sentral window. But I want to add another widget through the designer. How can I bring the console on this widget?


  • Lifetime Qt Champion

    you could use the promote feature

    So set a new central widget, add a layout to it.
    add a Qwidget as place holder and promote it to a console.

    Then when you run, it will be the console.

    Promote is sort of like replace at runtime.

  • Instead of setting console object as centralWidget , you just set simple Qwidget object as a centralWidget and then take one layout(QHboxLayout or QvboxLayout) and add your console object and newly created ui object using designer to that layout and set this layout to Qwidget object which you have set as centalwidget. it will resolve your problem.

  • @Venkatesh-V
    Thank for your answer! How I can this realize?
    Now I have this arrangement. At the top of the graph, and want to add the console down.
    alt text
    My code just in case: project on github

Log in to reply