- 信号是给槽函数传参的,信号函数只需声明,不需定义
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
//菜单栏
QMenuBar *mBar=new QMenuBar(this);
//添加菜单
QMenu *pFile = mBar->addMenu("文件");
//添加菜单项,添加动作
QAction *pNew=pFile->addAction("新建");
connect(pNew,&QAction::triggered,
[=]()
{
qDebug("push");
});
pFile->addSeparator();//添加分割线
QAction *popen=pFile->addAction("打开");
//工具栏,菜单上的快捷方式
QToolBar *toolbar=addToolBar("toolbar");
//工具栏添加快捷键
toolbar->addAction(pNew);
//添加小控件
QPushButton *b=new QPushButton(this);
b->setText("123");
toolbar->addWidget(b);
connect(b,&QPushButton::clicked,
[=]()
{
b->setText("345");
});
//状态栏
QStatusBar *sbar=new QStatusBar(this);
QLabel *label=new QLabel(this);
label->setText("Normal text file");
sbar->addWidget(label);
//addWidget 从左往右添加
sbar->addWidget(new QLabel("2",this));
//从右往左添加
sbar->addPermanentWidget(new QLabel("3",this));
//核心控件
QTextEdit *textEdit = new QTextEdit(this);
setCentralWidget(textEdit);
//浮动窗口
QDockWidget *dock=new QDockWidget(this);
addDockWidget(Qt::RightDockWidgetArea,dock);
//给浮动窗口添加控件
QTextEdit *textEdit1 = new QTextEdit();
dock->setWidget(textEdit1);
}
MainWindow::~MainWindow()
{
}
All articles in this blog are licensed under CC BY-NC-SA 4.0 unless stating additionally.