Qt设计师怎么给QWidget窗体添加QToolBar工具栏/QMenuBar菜单栏?

792 阅读1分钟

目前Qt设计师界面想添加工具栏,都是在QMainwindow中。而在QWidget中,并没有添加Qtoolbar的选项。由于项目的需要,需在QWidget添加toolbar。经尝试,可以用以下的方法添加。

在这里插入图片描述

在QWidget窗体中,随便在左侧WidgetBox找一个Widget控件拉到窗体中。

用文本编辑,找到刚才创建的对象,把QWidget改为QToolbar就可以了。

在这里插入图片描述

在这里插入图片描述
保存后,在此打开.ui文件。就可以在QtDesigner中,把QAction添加到工具栏中了。

在这里插入图片描述

 

同理,QMenuBar,QStatusBar也是一样的。

  <widget class="QToolBar" name="toolBar_1">
   <property name="windowTitle">
    <string>toolBar</string>
   </property>
   <attribute name="toolBarArea">
    <enum>TopToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
  </widget>

  <widget class="QToolBar" name="toolBar_2">
   <property name="windowTitle">
    <string>toolBar_2</string>
   </property>
   <attribute name="toolBarArea">
    <enum>LeftToolBarArea</enum>
   </attribute>
   <attribute name="toolBarBreak">
    <bool>false</bool>
   </attribute>
   <addaction name="actionTwoPoints"/>
  </widget>

 

 

————————————————
版权声明:本文为CSDN博主「landon611」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:blog.csdn.net/u011571773/…