1、菜单栏
QMenu * editMenu = ui-> menuBar-> addMenu ( "编辑(&E)" ) ;
2、编辑菜单栏及工具栏内容
QAction * action_copy = editMenu-> addAction ( QIcon ( "copy.png" ) , QString ( "复制(&c)" ) ) ;
action_copy-> setShortcut ( QKeySequence ( "ctrl + c" ) ) ;
ui-> mainToolBar-> addAction ( action_copy) ;
3、加入分组
QActionGroup * group = new QActionGroup ( this ) ;
QAction * action_L = group-> addAction ( "左对齐(&L)" ) ;
QAction * action_R = group-> addAction ( "右对齐(&R)" ) ;
QAction * action_C = group-> addAction ( "居中对齐(&C)" ) ;
QAction * action_J = group-> addAction ( "两端对齐(&J)" ) ;
action_J-> setCheckable ( true ) ;
action_R-> setCheckable ( true ) ;
action_C-> setCheckable ( true ) ;
action_J-> setCheckable ( true ) ;
editMenu-> addSeparator ( ) ;
editMenu-> addAction ( action_L) ;
editMenu-> addAction ( action_R) ;
editMenu-> addAction ( action_C) ;
editMenu-> addAction ( action_J) ;
4、工具栏添加部件,下拉框
QToolButton * toolBtn = new QToolButton ( this ) ;
toolBtn-> setText ( "颜色" ) ;
QMenu * colorMenu = new QMenu ( this ) ;
colorMenu-> addAction ( "红色" ) ;
colorMenu-> addAction ( "蓝色" ) ;
toolBtn-> setMenu ( colorMenu) ;
toolBtn-> setPopupMode ( QToolButton:: MenuButtonPopup) ;
ui-> mainToolBar-> addWidget ( toolBtn) ;
5、数字框
QSpinBox * spinBox = new QSpinBox ( this ) ;
ui-> mainToolBar-> addWidget ( spinBox) ;
6、状态栏设置提醒
ui-> statusBar-> showMessage ( QString ( "欢迎进入" ) , 3000 ) ;
7、永久提醒部件
QLabel * tag = new QLabel ( "www.7766.com" ) ;
ui-> statusBar-> addPermanentWidget ( tag) ;