diff --git a/DialogTest/.gitignore b/DialogTest/.gitignore new file mode 100644 index 0000000..fab7372 --- /dev/null +++ b/DialogTest/.gitignore @@ -0,0 +1,73 @@ +# This file is used to ignore files which are generated +# ---------------------------------------------------------------------------- + +*~ +*.autosave +*.a +*.core +*.moc +*.o +*.obj +*.orig +*.rej +*.so +*.so.* +*_pch.h.cpp +*_resource.rc +*.qm +.#* +*.*# +core +!core/ +tags +.DS_Store +.directory +*.debug +Makefile* +*.prl +*.app +moc_*.cpp +ui_*.h +qrc_*.cpp +Thumbs.db +*.res +*.rc +/.qmake.cache +/.qmake.stash + +# qtcreator generated files +*.pro.user* + +# xemacs temporary files +*.flc + +# Vim temporary files +.*.swp + +# Visual Studio generated files +*.ib_pdb_index +*.idb +*.ilk +*.pdb +*.sln +*.suo +*.vcproj +*vcproj.*.*.user +*.ncb +*.sdf +*.opensdf +*.vcxproj +*vcxproj.* + +# MinGW generated files +*.Debug +*.Release + +# Python byte code +*.pyc + +# Binaries +# -------- +*.dll +*.exe + diff --git a/DialogTest/DialogTest.pro b/DialogTest/DialogTest.pro new file mode 100644 index 0000000..feb215b --- /dev/null +++ b/DialogTest/DialogTest.pro @@ -0,0 +1,28 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + widget.cpp + +HEADERS += \ + widget.h + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target diff --git a/DialogTest/main.cpp b/DialogTest/main.cpp new file mode 100644 index 0000000..b0a4ec2 --- /dev/null +++ b/DialogTest/main.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + Widget w; + w.show(); + return a.exec(); +} diff --git a/DialogTest/widget.cpp b/DialogTest/widget.cpp new file mode 100644 index 0000000..7350ff4 --- /dev/null +++ b/DialogTest/widget.cpp @@ -0,0 +1,11 @@ +#include "widget.h" + +Widget::Widget(QWidget *parent) + : QWidget(parent) +{ +} + +Widget::~Widget() +{ +} + diff --git a/DialogTest/widget.h b/DialogTest/widget.h new file mode 100644 index 0000000..47b6270 --- /dev/null +++ b/DialogTest/widget.h @@ -0,0 +1,14 @@ +#ifndef WIDGET_H +#define WIDGET_H + +#include + +class Widget : public QWidget +{ + Q_OBJECT + +public: + Widget(QWidget *parent = nullptr); + ~Widget(); +}; +#endif // WIDGET_H diff --git a/qtdemo02/images/Edit.png b/qtdemo02/images/Edit.png new file mode 100644 index 0000000..07e386d Binary files /dev/null and b/qtdemo02/images/Edit.png differ diff --git a/qtdemo02/images/Frame.jpg b/qtdemo02/images/Frame.jpg new file mode 100644 index 0000000..0ebb428 Binary files /dev/null and b/qtdemo02/images/Frame.jpg differ diff --git a/qtdemo02/images/Left.png b/qtdemo02/images/Left.png new file mode 100644 index 0000000..e638f97 Binary files /dev/null and b/qtdemo02/images/Left.png differ diff --git a/qtdemo02/images/Luffy.png b/qtdemo02/images/Luffy.png new file mode 100644 index 0000000..f0410d8 Binary files /dev/null and b/qtdemo02/images/Luffy.png differ diff --git a/qtdemo02/images/LuffyQ.png b/qtdemo02/images/LuffyQ.png new file mode 100644 index 0000000..580a2e5 Binary files /dev/null and b/qtdemo02/images/LuffyQ.png differ diff --git a/qtdemo02/images/New.png b/qtdemo02/images/New.png new file mode 100644 index 0000000..5a6574f Binary files /dev/null and b/qtdemo02/images/New.png differ diff --git a/qtdemo02/images/OnePiece.png b/qtdemo02/images/OnePiece.png new file mode 100644 index 0000000..f64ca90 Binary files /dev/null and b/qtdemo02/images/OnePiece.png differ diff --git a/qtdemo02/images/Pause.png b/qtdemo02/images/Pause.png new file mode 100644 index 0000000..550be9f Binary files /dev/null and b/qtdemo02/images/Pause.png differ diff --git a/qtdemo02/images/Right.png b/qtdemo02/images/Right.png new file mode 100644 index 0000000..8885e22 Binary files /dev/null and b/qtdemo02/images/Right.png differ diff --git a/qtdemo02/images/Start.png b/qtdemo02/images/Start.png new file mode 100644 index 0000000..a2fd225 Binary files /dev/null and b/qtdemo02/images/Start.png differ diff --git a/qtdemo02/images/Sunny.jpg b/qtdemo02/images/Sunny.jpg new file mode 100644 index 0000000..1eea0c4 Binary files /dev/null and b/qtdemo02/images/Sunny.jpg differ diff --git a/qtdemo02/images/add.png b/qtdemo02/images/add.png new file mode 100644 index 0000000..8c41538 Binary files /dev/null and b/qtdemo02/images/add.png differ diff --git a/qtdemo02/images/butterfly.png b/qtdemo02/images/butterfly.png new file mode 100644 index 0000000..f3e050e Binary files /dev/null and b/qtdemo02/images/butterfly.png differ diff --git a/qtdemo02/images/butterfly1.png b/qtdemo02/images/butterfly1.png new file mode 100644 index 0000000..573f63c Binary files /dev/null and b/qtdemo02/images/butterfly1.png differ diff --git a/qtdemo02/images/cleanport.png b/qtdemo02/images/cleanport.png new file mode 100644 index 0000000..c1bf216 Binary files /dev/null and b/qtdemo02/images/cleanport.png differ diff --git a/qtdemo02/images/down.png b/qtdemo02/images/down.png new file mode 100644 index 0000000..4fc666e Binary files /dev/null and b/qtdemo02/images/down.png differ diff --git a/qtdemo02/images/logo.png b/qtdemo02/images/logo.png new file mode 100644 index 0000000..76b7fe2 Binary files /dev/null and b/qtdemo02/images/logo.png differ diff --git a/qtdemo02/images/mario.gif b/qtdemo02/images/mario.gif new file mode 100644 index 0000000..c38a831 Binary files /dev/null and b/qtdemo02/images/mario.gif differ diff --git a/qtdemo02/images/mesage.png b/qtdemo02/images/mesage.png new file mode 100644 index 0000000..89b7c80 Binary files /dev/null and b/qtdemo02/images/mesage.png differ diff --git a/qtdemo02/images/open.png b/qtdemo02/images/open.png new file mode 100644 index 0000000..1282b1e Binary files /dev/null and b/qtdemo02/images/open.png differ diff --git a/qtdemo02/images/reload.png b/qtdemo02/images/reload.png new file mode 100644 index 0000000..4a80a85 Binary files /dev/null and b/qtdemo02/images/reload.png differ diff --git a/qtdemo02/images/save.png b/qtdemo02/images/save.png new file mode 100644 index 0000000..4e33bd4 Binary files /dev/null and b/qtdemo02/images/save.png differ diff --git a/qtdemo02/images/stop.png b/qtdemo02/images/stop.png new file mode 100644 index 0000000..8178019 Binary files /dev/null and b/qtdemo02/images/stop.png differ diff --git a/qtdemo02/images/sunny.png b/qtdemo02/images/sunny.png new file mode 100644 index 0000000..4a7f5f5 Binary files /dev/null and b/qtdemo02/images/sunny.png differ diff --git a/qtdemo02/images/time.png b/qtdemo02/images/time.png new file mode 100644 index 0000000..b62bdca Binary files /dev/null and b/qtdemo02/images/time.png differ diff --git a/qtdemo02/images/up.png b/qtdemo02/images/up.png new file mode 100644 index 0000000..b909596 Binary files /dev/null and b/qtdemo02/images/up.png differ diff --git a/qtdemo02/images/write2file.png b/qtdemo02/images/write2file.png new file mode 100644 index 0000000..1d82305 Binary files /dev/null and b/qtdemo02/images/write2file.png differ diff --git a/qtdemo02/main.cpp b/qtdemo02/main.cpp new file mode 100644 index 0000000..fd3e533 --- /dev/null +++ b/qtdemo02/main.cpp @@ -0,0 +1,11 @@ +#include "mainwindow.h" + +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MainWindow w; + w.show(); + return a.exec(); +} diff --git a/qtdemo02/mainwindow.cpp b/qtdemo02/mainwindow.cpp new file mode 100644 index 0000000..ce2e396 --- /dev/null +++ b/qtdemo02/mainwindow.cpp @@ -0,0 +1,111 @@ +#include "mainwindow.h" +#include + +MainWindow::MainWindow(QWidget *parent) + : QMainWindow(parent) +{ + // 设置窗口的标题 + setWindowTitle("正在学习QMainWindow"); + resize(1200,960); + + // 创建菜单栏(QMenuBar,QMenu,QAction) + QMenuBar *menu_bar = menuBar(); + this->setMenuBar(menu_bar); // 设置当前窗口的菜单栏 + + // 创建图片空间 + QPixmap pix_map; + pix_map.load(":icon/start"); + + // 创建菜单 + QMenu *menu1 = new QMenu("文件",this); + // 创建菜单项 + QAction *openAction = menu1->addAction("打开..."); + QMenu *sub_menu = new QMenu("最近使用",this); // 子菜单 + sub_menu->addAction("d:\\a.txt"); + // 添加子菜单(菜单项也可以是一个菜单,即为子菜单) + menu1->addMenu(sub_menu); + QAction *newAction = menu1->addAction("新建..."); + menu1->addSeparator(); + newAction->setIcon(QIcon(pix_map)); + QAction *exitAction = menu1->addAction("退出"); + menu_bar->addMenu(menu1); + exitAction->setIcon(QIcon(":icon/stop")); + + + QMenu *menu2 = new QMenu("编辑",this); + QAction *editAction = menu2->addAction("复制"); + menu2->addAction("剪切"); + menu2->addAction("粘贴"); + + menu_bar->addMenu(menu2); + + // 菜单项的快捷方式 + openAction->setShortcut(QKeySequence(Qt::CTRL+Qt::Key_O)); + newAction->setShortcut(QKeySequence(tr("ctrl+n"))); + exitAction->setShortcut(QKeySequence(tr("ctrl+q"))); + + // 初始化子控件 + mEdit = new QTextEdit(this); + mEdit->hide(); + mWidget1 = new Widget1; + + connect(openAction,&QAction::triggered,[=](){ + takeCentralWidget(); // 将当前中心空间从主窗口移除 + qDebug()<<"正在打开文件..."; + setCentralWidget(mEdit); + mEdit->show(); + + }); + connect(newAction,&QAction::triggered,[=](){ + takeCentralWidget(); + qDebug()<<"正在新建文件..."; + setCentralWidget(mWidget1); + + }); + connect(exitAction,&QAction::triggered,this,&QMainWindow::close); + + // 工具栏 + QToolBar *tool_bar = new QToolBar; + tool_bar->setParent(this); + tool_bar->addAction(openAction); + tool_bar->addAction(newAction); + tool_bar->addSeparator(); + tool_bar->addAction(exitAction); + tool_bar->setMovable(false); // 禁止拖动 + tool_bar->setFloatable(false); // 禁止浮动 + tool_bar->setAllowedAreas(Qt::LeftToolBarArea|Qt::RightToolBarArea); + this->addToolBar(tool_bar); + // this->addToolBar(Qt::LeftToolBarArea,tool_bar); + + + // 创建状态栏 + QStatusBar *status_bar = new QStatusBar(this); + setStatusBar(status_bar); + QLabel *label1 = new QLabel("状态: 1",this); + status_bar->addWidget(label1); // 从左向右添加 + QLabel *label2 = new QLabel("状态: 2",this); + // label2->setFixedSize(200,40); + // label2->setStyleSheet("background-color: #cf0f13; padding-left: 100px;"); + status_bar-> addPermanentWidget(label2); // 从右向左添加 + status_bar->addWidget(new QLabel("状态 3: 0",this),1); // 1 是平铺剩余空间 + + + // 创建铆接控件 + QDockWidget *dock = new QDockWidget("铆接1",this); + dock->addAction(openAction); + dock->addAction(exitAction); + dock->setWidget(new Widget1(this)); + QDockWidget *dock2 = new QDockWidget("铆接2",this); + dock2->setWidget(new QPushButton("点我试试",this)); + addDockWidget(Qt::TopDockWidgetArea,dock); + addDockWidget(Qt::TopDockWidgetArea,dock2); + + + // 中心部件 + +} + +MainWindow::~MainWindow() +{ +} + diff --git a/qtdemo02/mainwindow.h b/qtdemo02/mainwindow.h new file mode 100644 index 0000000..6d7a950 --- /dev/null +++ b/qtdemo02/mainwindow.h @@ -0,0 +1,28 @@ +#ifndef MAINWINDOW_H +#define MAINWINDOW_H + +#include +#include // 菜单栏 +#include // 菜单 +#include // 菜单项 +#include +#include // 工具栏 +#include // 状态栏 +#include // 标签 +#include // 铆接控件 +#include +#include "widget1.h" +#include +#include // 图片 + +class MainWindow : public QMainWindow +{ + Q_OBJECT + QTextEdit *mEdit; + Widget1 *mWidget1; + +public: + MainWindow(QWidget *parent = nullptr); + ~MainWindow(); +}; +#endif // MAINWINDOW_H diff --git a/qtdemo02/qtdemo02.pro b/qtdemo02/qtdemo02.pro new file mode 100644 index 0000000..d958105 --- /dev/null +++ b/qtdemo02/qtdemo02.pro @@ -0,0 +1,34 @@ +QT += core gui + +greaterThan(QT_MAJOR_VERSION, 4): QT += widgets + +CONFIG += c++11 + +# The following define makes your compiler emit warnings if you use +# any Qt feature that has been marked deprecated (the exact warnings +# depend on your compiler). Please consult the documentation of the +# deprecated API in order to know how to port your code away from it. +DEFINES += QT_DEPRECATED_WARNINGS + +# You can also make your code fail to compile if it uses deprecated APIs. +# In order to do so, uncomment the following line. +# You can also select to disable deprecated APIs only up to a certain version of Qt. +#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 + +SOURCES += \ + main.cpp \ + mainwindow.cpp \ + widget1.cpp + +HEADERS += \ + mainwindow.h \ + widget1.h + +# Default rules for deployment. +qnx: target.path = /tmp/$${TARGET}/bin +else: unix:!android: target.path = /opt/$${TARGET}/bin +!isEmpty(target.path): INSTALLS += target + +RESOURCES += \ + res.qrc + diff --git a/qtdemo02/res.qrc b/qtdemo02/res.qrc new file mode 100644 index 0000000..77942d4 --- /dev/null +++ b/qtdemo02/res.qrc @@ -0,0 +1,8 @@ + + + images/open.png + images/save.png + images/Start.png + images/stop.png + + diff --git a/qtdemo02/widget1.cpp b/qtdemo02/widget1.cpp new file mode 100644 index 0000000..4ed4470 --- /dev/null +++ b/qtdemo02/widget1.cpp @@ -0,0 +1,26 @@ +#include "widget1.h" + +Widget1::Widget1(QWidget *parent) : QWidget(parent) +{ + btn = new QPushButton("Ok",this); + close_btn = new QPushButton("退出",this); + label = new QLabel("结果: ",this); + + btn->resize(100,50); + btn->move(10,10); + + close_btn->resize(100,50); + close_btn->move(120,10); + + label->resize(200,50); + label->move(10,70); + + connect(btn,&QPushButton::pressed,[&](){ + label->setText("结果: 1+1 = 2"); + }); + + connect(close_btn,&QPushButton::pressed,[&](){ + this->close(); + }); + +} diff --git a/qtdemo02/widget1.h b/qtdemo02/widget1.h new file mode 100644 index 0000000..0c0a5ef --- /dev/null +++ b/qtdemo02/widget1.h @@ -0,0 +1,22 @@ +#ifndef WIDGET1_H +#define WIDGET1_H + +#include +#include +#include + +class Widget1 : public QWidget +{ + Q_OBJECT + QPushButton *btn; // 私有 + QLabel *label; + QPushButton *close_btn; + +public: + explicit Widget1(QWidget *parent = nullptr); + +signals: + +}; + +#endif // WIDGET1_H