Home > database >  How to add a central widget, menubar and statusbar to a "Qt Widgets Class" created by the
How to add a central widget, menubar and statusbar to a "Qt Widgets Class" created by the

Time:03-10

After adding a "Qt Widgets Class" in Visual Studio, I would like to add a central widget, a menubar and a status bar in Qt Designer, but I see no such items neither in the Widget Box nor in the context menu of the top-level QWidget added by the wizard. How I add these items?

CodePudding user response:

  1. Open the .ui file with a text editor, such as notepad.exe and change this:

    <widget  ... >
    to this:
    <widget  ... >

  2. Add the "centralWidget" within the QMainWindow widget:

    <widget   name="centralWidget"... >...</widget>
  3. Now you can add a menubar, toolbar and statusbar from the context menu associated with the QMainWindow widget:

enter image description here

CodePudding user response:

Open your widget's .ui file with Qt Creator, and add the needed widgets to your widget.

To add menubar, right click the most parent item of your widget on object tree as seems below, and select "Create Menu Bar". To add status bar, this time select "Create Status Bar" on the same menu.

widget tree

  •  Tags:  
  • c qt
  • Related