Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. setCentralWidget() for an arbitrary widget
Qt 6.11 is out! See what's new in the release blog

setCentralWidget() for an arbitrary widget

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 1.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maratk1n
    wrote on last edited by maratk1n
    #1

    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\terminal.pro).
    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?

    Thanks!

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      you could use the promote feature
      http://doc.qt.io/qt-4.8/designer-using-custom-widgets.html

      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.

      1 Reply Last reply
      3
      • Venkatesh VV Offline
        Venkatesh VV Offline
        Venkatesh V
        wrote on last edited by
        #3

        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.

        M 1 Reply Last reply
        1
        • Venkatesh VV Venkatesh V

          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.

          M Offline
          M Offline
          maratk1n
          wrote on last edited by maratk1n
          #4

          @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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved