代码拉取完成,页面将自动刷新
#include "mainwindow.h"
#include <QtWidgets>
#include <QDebug>
#include <finddialog.h>
#include <findfiledialog.h>
#include <findfiledialog2.h>
#include <findfiledialog3.h>
#include <preferencedialog.h>
#include <mailclient.h>
#include <ticker.h>
#include "qmywidget.h"
MainWindow::MainWindow()
{
//设置窗口属性
resize(1100,800);
setWindowTitle(tr("我的应用"));
//创建菜单栏
const QIcon icon = QIcon(":/images/new.png");
QMenu *coreMenu = menuBar()->addMenu(tr("&Qt核心"));
QAction *timeEventHandlerAction=new QAction(icon, tr("&定时器事件"), this);
timeEventHandlerAction->setStatusTip(tr("eventHandler"));
connect(timeEventHandlerAction, &QAction::triggered, this, &MainWindow::eventHandler);//连接信号与槽
coreMenu->addAction(timeEventHandlerAction);
QAction *metaObjectSystemAction=new QAction(icon, tr("&元对象系统"), this);
metaObjectSystemAction->setStatusTip(tr("metaObjectSystem"));
connect(metaObjectSystemAction, &QAction::triggered, this, &MainWindow::metaObjectSystem);//连接信号与槽
coreMenu->addAction(metaObjectSystemAction);
QMenu *fileMenu = menuBar()->addMenu(tr("&对话框"));
QAction *createMessageBoxAction=new QAction(icon, tr("&消息对话框"), this);
createMessageBoxAction->setStatusTip(tr("createMessageBox"));
connect(createMessageBoxAction, &QAction::triggered, this, &MainWindow::createMessageBox);//连接信号与槽
fileMenu->addAction(createMessageBoxAction);
QAction *createCustomerDialogAction=new QAction(icon, tr("&自定义对话框"), this);
createCustomerDialogAction->setStatusTip(tr("createCustomerDialog"));
connect(createCustomerDialogAction, &QAction::triggered, this, &MainWindow::createCustomerDialog);//连接信号与槽
fileMenu->addAction(createCustomerDialogAction);
QMenu *layoutManagerMenu = menuBar()->addMenu(tr("&布局管理"));
QAction *absolutePositionAction=new QAction(icon, tr("&绝对位置布局"), this);
absolutePositionAction->setStatusTip(tr("layoutManager"));
connect(absolutePositionAction, &QAction::triggered, this, &MainWindow::absolutePosition);//连接信号与槽
layoutManagerMenu->addAction(absolutePositionAction);
QAction *manualLayoutAction=new QAction(icon, tr("&人工布局"), this);
manualLayoutAction->setStatusTip(tr("manualLayout"));
connect(manualLayoutAction, &QAction::triggered, this, &MainWindow::manualLayout);//连接信号与槽
layoutManagerMenu->addAction(manualLayoutAction);
QAction *layoutManagerAction=new QAction(icon, tr("&网格&线性布局"), this);
layoutManagerAction->setStatusTip(tr("manualLayout"));
connect(layoutManagerAction, &QAction::triggered, this, &MainWindow::layoutManager);//连接信号与槽
layoutManagerMenu->addAction(layoutManagerAction);
QAction *stackedLayoutAction=new QAction(icon, tr("&栈布局"), this);
stackedLayoutAction->setStatusTip(tr("stackedLayout"));
connect(stackedLayoutAction, &QAction::triggered, this, &MainWindow::stackedLayout);//连接信号与槽
layoutManagerMenu->addAction(stackedLayoutAction);
QAction *splitterAction=new QAction(icon, tr("&分离器切割"), this);
splitterAction->setStatusTip(tr("splitterAction"));
connect(splitterAction, &QAction::triggered, this, &MainWindow::splitter);//连接信号与槽
layoutManagerMenu->addAction(splitterAction);
QMenu *windowMenu = menuBar()->addMenu(tr("&窗口部件"));
//创建工具栏
QToolBar *fileToolBar = addToolBar(tr("File"));
fileToolBar->addAction(createMessageBoxAction);
//设置中央组件
textEdit=new QPlainTextEdit;
setCentralWidget(textEdit);
//显示状态栏
statusBar()->showMessage(tr("Ready"));
//创建悬浮窗口
createDockWindows();
}
void MainWindow::createMessageBox(){
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
switch (ret) {
case QMessageBox::Save:
// Save was clicked
statusBar()->showMessage(tr("Save was clicked"));
break;
case QMessageBox::Discard:
// Don't Save was clicked
statusBar()->showMessage(tr("Don't Save was clicked"));
break;
case QMessageBox::Cancel:
// Cancel was clicked
statusBar()->showMessage(tr("Cancel was clicked"));
break;
default:
// should never be reached
break;
}
}
void MainWindow::createCustomerDialog(){
FindDialog *findDialog=new FindDialog(this);
findDialog->show();
}
void MainWindow::absolutePosition(){
FindFileDialog *findFileDialog=new FindFileDialog(this);
findFileDialog->show();
}
void MainWindow::manualLayout(){
FindFileDialog2 *findFileDialog2=new FindFileDialog2(this);
findFileDialog2->show();
}
void MainWindow::layoutManager(){
FindFileDialog3 *findFileDialog3=new FindFileDialog3(this);
findFileDialog3->show();
}
void MainWindow::stackedLayout(){
PreferenceDialog *dialog=new PreferenceDialog(this);
dialog->show();
}
void MainWindow::splitter(){
MailClient *mailClient=new MailClient();
mailClient->show();
}
void MainWindow::metaObjectSystem(){
QmyWidget *w=new QmyWidget;
w->show();
}
void MainWindow::eventHandler(){
Ticker *ticker=new Ticker();
ticker->setWindowTitle(QObject::tr("Ticker"));
ticker->setText(QObject::tr("How long it lasted was impossible to "
"say ++ "));
ticker->show();
}
void MainWindow::createDockWindows()
{
QDockWidget *leftDock = new QDockWidget(tr("Customers"), this);
leftDock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
customerList = new QListWidget(leftDock);
customerList->addItems(QStringList()
<< "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
<< "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
<< "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
<< "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
<< "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
<< "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
leftDock->setWidget(customerList);
addDockWidget(Qt::LeftDockWidgetArea, leftDock);
QDockWidget *rightDock = new QDockWidget(tr("Paragraphs"), this);
paragraphsList = new QListWidget(rightDock);
paragraphsList->addItems(QStringList()
<< "Thank you for your payment which we have received today."
<< "Your order has been dispatched and should be with you "
"within 28 days."
<< "We have dispatched those items that were in stock. The "
"rest of your order will be dispatched once all the "
"remaining items have arrived at our warehouse. No "
"additional shipping charges will be made."
<< "You made a small overpayment (less than $5) which we "
"will keep on account for you, or return at your request."
<< "You made a small underpayment (less than $1), but we have "
"sent your order anyway. We'll add this underpayment to "
"your next bill."
<< "Unfortunately you did not send enough money. Please remit "
"an additional $. Your order will be dispatched as soon as "
"the complete amount has been received."
<< "You made an overpayment (more than $5). Do you wish to "
"buy more items, or should we return the excess to you?");
rightDock->setWidget(paragraphsList);
addDockWidget(Qt::RightDockWidgetArea, rightDock);
}
void MainWindow::closeEvent(QCloseEvent *event){
qDebug()<<"closeEvent";
}
void MainWindow::print()
{
statusBar()->showMessage(tr("Ready"), 2000);
}
MainWindow::~MainWindow()
{
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。