QT5 四,Qmainwindow设置问题

MainWindow::MainWindow(QWidget *parent)
QMainWindow(parent)
{
this->resize(800,500);
this->setFixedSize(800,500);
//菜单栏 只有一个
QMenuBar *menu= menuBar();//创建一个菜单栏
setMenuBar(menu);//将菜单栏设置到窗口中
QMenu *filemenu=menu->addMenu("文件");//横向的添加菜单栏
QMenu *editmenu=menu->addMenu("编辑");//横向的添加菜单栏

QAction *openAction=filemenu->addAction("打开");//纵向添加菜单下拉项
filemenu->addSeparator();//添加分割线
QAction *saveAction=filemenu->addAction("保存");

QAction *edittool=editmenu->addAction("附加工具");

//工具栏 可以多个
QToolBar *toolbar=new QToolBar(this);//增加工具栏
addToolBar(toolbar);//将工具栏设置到窗口中

addToolBar(Qt::LeftToolBarArea,toolbar);//可以固定区域
toolbar->setAllowedAreas(Qt::TopToolBarArea|Qt::LeftToolBarArea);//只允许上左拉动
toolbar->setFloatable(false);//设置浮动
toolbar->setMovable(false);//设置移动,不让其移动

QPushButton *button1=new QPushButton("open",this);
toolbar->addWidget(button1);//在工具栏加入按钮
//button1->setText("open");//这样写会出现显示不全
//button1->setParent(toolbar);同上

QAction *toolopen=toolbar->addAction(“打开”);//在工具栏添加菜单项
toolbar->addSeparator();//添加分割线
QAction *toolclose=toolbar->addAction(“关闭”);

//状态栏只有一个
QStatusBar *statubar=statusBar();//创建新的状态栏
setStatusBar(statubar);//将状态栏放入窗口

QLabel *statulabel=new QLabel(“左侧信息”,this);//添加新标签到状态栏
statubar->addWidget(statulabel);
QLabel *statulabel2=new QLabel(“右侧信息”,this);//添加右侧新标签
statubar->addPermanentWidget(statulabel2);//把标签放到右边

//铆接部件 浮动窗口 可以多个
QDockWidget *newdock=new QDockWidget(“浮动窗口”,this);
addDockWidget(Qt::TopDockWidgetArea,newdock);
newdock->setAllowedAreas(Qt::TopDockWidgetArea|Qt::RightDockWidgetArea);//设置停靠范围

//核心部件 只有一个

QTextEdit *edit=new QTextEdit(“核心”,this);
setCentralWidget(edit);

//总结:1,只能有一个的(菜单栏,状态栏,核心部件),创建时都是=后面加个系统自带的函数xx(),当添加进入窗口的时候都是setxxx,
// 2,如果可以有多的(工具栏,浮动窗口),创建的时候都是=后面加new xxx,当添加窗口都是addxxx,

}

MainWindow::~MainWindow()
{

}

你可能感兴趣的:(QT5 四,Qmainwindow设置问题)