├── CodeDemo ├── CH1 │ ├── CH101 │ │ └── Dialog │ │ │ ├── Dialog.pro │ │ │ ├── Dialog.pro.user │ │ │ ├── dialog.cpp │ │ │ ├── dialog.h │ │ │ ├── dialog.ui │ │ │ └── main.cpp │ └── CH102 │ │ └── Dialog │ │ ├── Dialog.pro │ │ ├── Dialog.pro.user │ │ ├── dialog.cpp │ │ ├── dialog.h │ │ └── main.cpp ├── CH2 │ ├── CH203 │ │ └── STL_Iterator │ │ │ ├── STL_Iterator.pro │ │ │ ├── STL_Iterator.pro.user │ │ │ └── main.cpp │ ├── CH205 │ │ └── STL_Iterator │ │ │ ├── STL_Iterator.pro │ │ │ ├── STL_Iterator.pro.user │ │ │ └── main.cpp │ └── CH206 │ │ └── myVariant │ │ ├── main.cpp │ │ ├── myVariant.pro │ │ ├── myVariant.pro.user │ │ ├── widget.cpp │ │ └── widget.h ├── CH3 │ ├── CH301 │ │ └── Splitter │ │ │ ├── Splitter.pro │ │ │ ├── Splitter.pro.user │ │ │ ├── main.cpp │ │ │ ├── mainwindow.cpp │ │ │ └── mainwindow.h │ ├── CH302 │ │ └── DockWindows │ │ │ ├── DockWindows.pro │ │ │ ├── DockWindows.pro.user │ │ │ ├── dockwindows.cpp │ │ │ ├── dockwindows.h │ │ │ └── main.cpp │ ├── CH303 │ │ └── StackDlg │ │ │ ├── StackDlg.pro │ │ │ ├── StackDlg.pro.user │ │ │ ├── dialog.cpp │ │ │ ├── dialog.h │ │ │ └── main.cpp │ ├── CH304 │ │ └── UserInfo │ │ │ ├── UserInfo.pro │ │ │ ├── UserInfo.pro.user │ │ │ ├── dialog.cpp │ │ │ ├── dialog.h │ │ │ ├── head.png │ │ │ ├── head.qrc │ │ │ └── main.cpp │ └── CH305 │ │ └── LayoutExample │ │ ├── LayoutExample.pro │ │ ├── baseinfo.cpp │ │ ├── baseinfo.h │ │ ├── contact.cpp │ │ ├── contact.h │ │ ├── content.cpp │ │ ├── content.h │ │ ├── detail.cpp │ │ ├── detail.h │ │ ├── head.png │ │ ├── main.cpp │ │ └── sorces.qrc ├── CH4 │ ├── CH401 │ │ └── DialogExample │ │ │ ├── DialogExample.pro │ │ │ ├── DialogExample.pro.user │ │ │ ├── dialog.cpp │ │ │ ├── dialog.h │ │ │ ├── inputdlg.cpp │ │ │ ├── inputdlg.h │ │ │ ├── main.cpp │ │ │ ├── msgboxdlg.cpp │ │ │ └── msgboxdlg.h │ ├── CH402 │ │ └── QToolBoxExample │ │ │ ├── QToolBoxExample.pro │ │ │ ├── drawer.cpp │ │ │ ├── drawer.h │ │ │ ├── head.qrc │ │ │ ├── icon │ │ │ ├── 1.png │ │ │ ├── 2.png │ │ │ ├── 3.png │ │ │ ├── 4.png │ │ │ ├── 5.png │ │ │ ├── 6.png │ │ │ ├── 7.png │ │ │ ├── 8.png │ │ │ └── 9.png │ │ │ └── main.cpp │ ├── CH403 │ │ └── ProgressExample │ │ │ ├── ProgressExample.pro │ │ │ ├── main.cpp │ │ │ ├── progressdlg.cpp │ │ │ └── progressdlg.h │ ├── CH404 │ │ └── PaletteExample │ │ │ ├── PaletteExample.pro │ │ │ ├── main.cpp │ │ │ ├── palette.cpp │ │ │ └── palette.h │ ├── CH405 │ │ └── ClockExample │ │ │ ├── ClockExample.pro │ │ │ ├── digiclock.cpp │ │ │ ├── digiclock.h │ │ │ └── main.cpp │ ├── CH406 │ │ └── ExtensibleDialogExample │ │ │ ├── ExtensibleDialogExample.pro │ │ │ ├── extensibledlg.cpp │ │ │ ├── extensibledlg.h │ │ │ └── main.cpp │ └── CH407 │ │ └── IrregularShapeExample │ │ ├── IrregularShapeExample.pro │ │ ├── main.cpp │ │ ├── shape.png │ │ ├── shapewidget.cpp │ │ ├── shapewidget.h │ │ └── sources.qrc ├── CH5 │ ├── CH501 │ │ └── SimpleTextEditor │ │ │ ├── Resource.qrc │ │ │ ├── SimpleTextEditor.pro │ │ │ ├── icon │ │ │ ├── bold.png │ │ │ ├── center.png │ │ │ ├── color.png │ │ │ ├── copy.png │ │ │ ├── cut.png │ │ │ ├── italic.png │ │ │ ├── justify.png │ │ │ ├── left.png │ │ │ ├── new.png │ │ │ ├── open.png │ │ │ ├── paste.png │ │ │ ├── printText.png │ │ │ ├── redo.png │ │ │ ├── right.png │ │ │ ├── underline.png │ │ │ └── undo.png │ │ │ ├── main.cpp │ │ │ ├── showwidget.cpp │ │ │ ├── showwidget.h │ │ │ ├── simpletexteditor.cpp │ │ │ └── simpletexteditor.h │ └── QMainWindowTest │ │ └── QMainWindowTest │ │ ├── QMainWindowTest.pro │ │ ├── main.cpp │ │ ├── mainwindow.cpp │ │ └── mainwindow.h └── CH6 │ ├── CH601 │ └── CoordinateExample │ │ ├── CoordinateExample.pro │ │ ├── coordinate.cpp │ │ ├── coordinate.h │ │ └── main.cpp │ ├── CH602 │ └── QPainterSimpleExample │ │ ├── QPainterSimpleExample.pro │ │ ├── Resource.qrc │ │ ├── displayarea.cpp │ │ ├── displayarea.h │ │ ├── main.cpp │ │ ├── qpaintersimpleexample.cpp │ │ ├── qpaintersimpleexample.h │ │ ├── shape.png │ │ └── texture.png │ └── CH603 │ └── DoubleBufferMechanism │ ├── DoubleBufferMechanism.pro │ ├── drawwidget.cpp │ ├── drawwidget.h │ ├── main.cpp │ ├── mainwindow.cpp │ └── mainwindow.h ├── Pictures ├── QT基础之GraphicsView图形视图框架介绍 │ ├── A_QT基础之GraphicsView图形视图框架介绍.png │ ├── B_QT基础之GraphicsView图形视图框架介绍.png │ ├── C_QT基础之GraphicsView图形视图框架介绍.png │ └── D_QT基础之GraphicsView图形视图框架介绍.png ├── QT基础之QLayout综合实例 │ ├── A_QT基础之QLayout综合实例.png │ ├── B_QT基础之QLayout综合实例.png │ ├── C_QT基础之QLayout综合实例.png │ ├── D_QT基础之QLayout综合实例.png │ ├── E_QT基础之QLayout综合实例.png │ └── 布局框架.eddx ├── QT基础之QPalette实例电子时钟 │ ├── A_QT基础之QPalette实例电子时钟.png │ └── B_QT基础之QPalette实例电子时钟.gif ├── QT基础之QPalette类 │ ├── A_QT基础之QPalette类.png │ ├── B_QT基础之QPalette类.png │ ├── C_QT基础之QPalette类.png │ └── D_QT基础之QPalette类.png ├── QT基础之QT5.12下载与安装 │ ├── A_QT基础之QT5.12下载与安装.png │ ├── B_QT基础之QT5.12下载与安装.png │ ├── C_QT基础之QT5.12下载与安装.png │ ├── D_QT基础之QT5.12下载与安装.png │ └── E_QT基础之QT5.12下载与安装.png ├── QT基础之QToolBox工具盒类 │ ├── A_QT基础之QToolBox工具盒类.png │ ├── B_QT基础之QToolBox工具盒类.png │ ├── C_QT基础之QToolBox工具盒类.png │ └── D_QT基础之QToolBox工具盒类.png ├── QT基础之一文介绍QPainter绘制基础图形 │ ├── A_QT基础之一文介绍QPainter绘制基础图形.png │ ├── B_QT基础之一文介绍QPainter绘制基础图形.png │ ├── C_QT基础之一文介绍QPainter绘制基础图形.png │ ├── D_QT基础之一文介绍QPainter绘制基础图形.png │ ├── E_QT基础之一文介绍QPainter绘制基础图形.png │ ├── F_QT基础之一文介绍QPainter绘制基础图形.png │ ├── G_QT基础之一文介绍QPainter绘制基础图形.png │ ├── H_QT基础之一文介绍QPainter绘制基础图形.png │ ├── I_QT基础之一文介绍QPainter绘制基础图形.png │ ├── J_QT基础之一文介绍QPainter绘制基础图形.png │ ├── K_QT基础之一文介绍QPainter绘制基础图形.png │ └── L_QT基础之一文介绍QPainter绘制基础图形.gif ├── QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式 │ ├── A_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── B_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── C_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── D_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── E_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif │ ├── F_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif │ ├── G_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── H_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── I_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif │ ├── J_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png │ ├── K_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif │ ├── L_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif │ └── 文本编辑器各类之间的划分与关系.eddx ├── QT基础之不规则窗体 │ ├── A_QT基础之不规则窗体.png │ ├── B_QT基础之不规则窗体.png │ └── C_QT基础之不规则窗体.gif ├── QT基础之主窗口构成 │ ├── A_QT基础之主窗口构成.png │ ├── B_QT基础之主窗口构成.png │ ├── C_QT基础之主窗口构成.png │ └── D_QT基础之主窗口构成.gif ├── QT基础之位置相关的函数介绍 │ ├── A_QT基础之位置相关的函数介绍.png │ ├── B_QT基础之位置相关的函数介绍.gif │ └── QT基础之位置相关的函数介绍.eddx ├── QT基础之停靠窗口QDockWidget类 │ ├── A_QT基础之停靠窗口QDockWidget类.PNG │ ├── B_QT基础之停靠窗口QDockWidget类.PNG │ ├── C_QT基础之停靠窗口QDockWidget类.PNG │ └── D_QT基础之停靠窗口QDockWidget类.gif ├── QT基础之分割窗口类QSplitter类 │ ├── A_QT基础之分割窗口类QSplitter类.gif │ └── B_QT基础之分割窗口类QSplitter类.gif ├── QT基础之双缓冲机制介绍 │ ├── A_QT基础之双缓冲机制介绍.png │ ├── B_QT基础之双缓冲机制介绍.png │ ├── C_QT基础之双缓冲机制介绍.png │ ├── D_QT基础之双缓冲机制介绍.gif │ └── QT基础之双缓冲机制介绍.eddx ├── QT基础之可扩展对话框 │ ├── A_QT基础之可扩展对话框.png │ └── B_QT基础之可扩展对话框.gif ├── QT基础之基本对话框 │ ├── A_QT基础之基本对话框.png │ ├── B_QT基础之基本对话框.png │ ├── C_QT基础之基本对话框.png │ ├── D_QT基础之基本对话框.png │ ├── E_QT基础之基本对话框.png │ ├── F_QT基础之基本对话框.png │ ├── G_QT基础之基本对话框.png │ └── H_QT基础之基本对话框.png ├── QT基础之基本布局QLayout │ ├── A_QT基础之基本布局QLayout.png │ ├── B_QT基础之基本布局QLayout.png │ ├── C_QT基础之基本布局QLayout.png │ ├── D_QT基础之基本布局QLayout.png │ ├── Demo布局框架.eddx │ ├── E_QT基础之基本布局QLayout.png │ ├── F_QT基础之基本布局QLayout.png │ ├── G_QT基础之基本布局QLayout.png │ └── H_QT基础之基本布局QLayout.png ├── QT基础之基础进度条 │ ├── A_QT基础之基础进度条.png │ └── B_QT基础之基础进度条.png ├── QT基础之堆栈窗体QStackedWidget类 │ └── A_QT基础之堆栈窗体QStackedWidget类.gif └── QT基础之常用控件简单介绍 │ ├── A_QT基础之常用控件简单介绍.png │ ├── B_QT基础之常用控件简单介绍.png │ ├── C_QT基础之常用控件简单介绍.png │ ├── D_QT基础之常用控件简单介绍.png │ ├── E_QT基础之常用控件简单介绍.png │ ├── F_QT基础之常用控件简单介绍.png │ ├── G_QT基础之常用控件简单介绍.png │ └── H_QT基础之常用控件简单介绍.png ├── QT基础之GraphicsView图形视图框架介绍.md ├── QT基础之QLayout综合实例.md ├── QT基础之QPalette实例电子时钟.md ├── QT基础之QPalette类.md ├── QT基础之QT5.12下载与安装.md ├── QT基础之QToolBox工具盒类.md ├── QT基础之QVariant类.md ├── QT基础之一文介绍QPainter绘制基础图形.md ├── QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.md ├── QT基础之不规则窗体.md ├── QT基础之主窗口构成.md ├── QT基础之位置相关的函数介绍.md ├── QT基础之信号与槽机制.md ├── QT基础之停靠窗口QDockWidget类.md ├── QT基础之分割窗口QSplitter类.md ├── QT基础之双缓冲机制介绍.md ├── QT基础之可扩展对话框.md ├── QT基础之基本对话框.md ├── QT基础之基本布局QLayout.md ├── QT基础之基础进度条.md ├── QT基础之堆栈窗体QStackedWidget类.md ├── QT基础之字符串类.md ├── QT基础之容器类.md ├── QT基础之常用控件简单介绍.md ├── QT基础之隐式共享.md ├── QT基础之默认main文件说明.md └── README.md /CodeDemo/CH1/CH101/Dialog/Dialog.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | dialog.cpp 14 | 15 | HEADERS += \ 16 | dialog.h 17 | 18 | FORMS += \ 19 | dialog.ui 20 | 21 | # Default rules for deployment. 22 | qnx: target.path = /tmp/$${TARGET}/bin 23 | else: unix:!android: target.path = /opt/$${TARGET}/bin 24 | !isEmpty(target.path): INSTALLS += target 25 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH101/Dialog/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include "ui_dialog.h" 3 | 4 | const static double PI = 3.1415926; 5 | 6 | Dialog::Dialog(QWidget *parent) 7 | : QDialog(parent) 8 | , ui(new Ui::Dialog) 9 | { 10 | ui->setupUi(this); 11 | } 12 | 13 | Dialog::~Dialog() 14 | { 15 | delete ui; 16 | } 17 | 18 | 19 | void Dialog::on_countBtn_clicked() 20 | { 21 | bool ok; 22 | QString tempStr; 23 | QString valueStr = ui->radiusLineEdit->text(); 24 | int valueInt = valueStr.toInt(&ok); 25 | double area = valueInt * valueInt * PI; 26 | ui->areaLabel_2->setText(tempStr.setNum(area)); 27 | } 28 | 29 | void Dialog::on_radiusLineEdit_textChanged(const QString &arg1) 30 | { 31 | bool ok; 32 | QString tempStr; 33 | QString valueStr = ui->radiusLineEdit->text(); 34 | int valueInt = valueStr.toInt(&ok); 35 | double area = valueInt * valueInt * PI; 36 | ui->areaLabel_2->setText(tempStr.setNum(area)); 37 | } 38 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH101/Dialog/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | 6 | QT_BEGIN_NAMESPACE 7 | namespace Ui { class Dialog; } 8 | QT_END_NAMESPACE 9 | 10 | class Dialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Dialog(QWidget *parent = nullptr); 16 | ~Dialog(); 17 | 18 | private slots: 19 | void on_countBtn_clicked(); 20 | 21 | void on_radiusLineEdit_textChanged(const QString &arg1); 22 | 23 | private: 24 | Ui::Dialog *ui; 25 | }; 26 | #endif // DIALOG_H 27 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH101/Dialog/dialog.ui: -------------------------------------------------------------------------------- 1 | 2 | 3 | Dialog 4 | 5 | 6 | 7 | 0 8 | 0 9 | 497 10 | 159 11 | 12 | 13 | 14 | Dialog 15 | 16 | 17 | 18 | 19 | 30 20 | 70 21 | 54 22 | 12 23 | 24 | 25 | 26 | 半径: 27 | 28 | 29 | 30 | 31 | 32 | 250 33 | 70 34 | 54 35 | 12 36 | 37 | 38 | 39 | 面积: 40 | 41 | 42 | 43 | 44 | 45 | 80 46 | 70 47 | 113 48 | 20 49 | 50 | 51 | 52 | 53 | 54 | 55 | 320 56 | 110 57 | 75 58 | 23 59 | 60 | 61 | 62 | PushButton 63 | 64 | 65 | 66 | 67 | 68 | 300 69 | 70 70 | 81 71 | 21 72 | 73 | 74 | 75 | QFrame::Panel 76 | 77 | 78 | QFrame::Sunken 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH101/Dialog/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Dialog w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH102/Dialog/Dialog.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | dialog.cpp 14 | 15 | HEADERS += \ 16 | dialog.h 17 | 18 | # Default rules for deployment. 19 | qnx: target.path = /tmp/$${TARGET}/bin 20 | else: unix:!android: target.path = /opt/$${TARGET}/bin 21 | !isEmpty(target.path): INSTALLS += target 22 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH102/Dialog/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include // 网格布局管理器 3 | 4 | const static double PI = 3.1415926; 5 | 6 | Dialog::Dialog(QWidget *parent) 7 | : QDialog(parent) 8 | { 9 | label1 = new QLabel(this); 10 | /* 11 | * 函数 tr()全名是QObject::tr(),被它处理的 字符串可以 使用工具提 取出来翻译 成其他语言, 也就是做国际化使用。 12 | * 只要记住,Qt 的最佳实践:如果你想让你的程序国际化的话,那么,所有用户可见的字符串都要使用 QObject::tr()! 13 | * 但是,为什么我们没有写 QObject::tr(),而仅仅是 tr()呢?原来,tr()函数是定义在 Object里面的,所有使用了 Q_OBJECT 宏的类都自动具有 tr()函数。 14 | */ 15 | label1->setText(tr("请输入圆的半径:")); 16 | 17 | lineEdit = new QLineEdit(this); 18 | label2 = new QLabel(this); 19 | button = new QPushButton(this); 20 | button->setText(tr("显示对应圆的面积")); 21 | 22 | QGridLayout *mainLayout = new QGridLayout(this); 23 | mainLayout->addWidget(label1,0,0); 24 | mainLayout->addWidget(lineEdit,0,1); 25 | mainLayout->addWidget(label2,1,0); 26 | mainLayout->addWidget(button,1,1); 27 | 28 | // 关联信号和槽函数 29 | connect(button,SIGNAL(clicked()),this,SLOT(showArea())); // 按钮点击 30 | 31 | connect(lineEdit,SIGNAL(textChanged(QString)),this,SLOT(showArea())); // 输入改变 32 | 33 | } 34 | 35 | Dialog::~Dialog() 36 | { 37 | } 38 | 39 | void Dialog::showArea() 40 | { 41 | bool ok; 42 | QString tempStr; 43 | QString valueStr = lineEdit->text(); 44 | int valueInt = valueStr.toInt(&ok); 45 | double area = valueInt * valueInt * PI; 46 | label2->setText(tempStr.setNum(area)); 47 | } 48 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH102/Dialog/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Dialog : public QDialog 10 | { 11 | Q_OBJECT //启动 QT5 元对象系统,必须放置到类定义的私有区 12 | 13 | public: 14 | Dialog(QWidget *parent = nullptr); 15 | ~Dialog(); 16 | private: 17 | QLabel *label1,*label2; 18 | QLineEdit *lineEdit; 19 | QPushButton *button; 20 | private slots: 21 | void showArea(); // 槽函数 22 | }; 23 | #endif // DIALOG_H 24 | -------------------------------------------------------------------------------- /CodeDemo/CH1/CH102/Dialog/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Dialog w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH203/STL_Iterator/STL_Iterator.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp 13 | 14 | HEADERS += 15 | 16 | # Default rules for deployment. 17 | qnx: target.path = /tmp/$${TARGET}/bin 18 | else: unix:!android: target.path = /opt/$${TARGET}/bin 19 | !isEmpty(target.path): INSTALLS += target 20 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH203/STL_Iterator/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main(int argc, char *argv[]) 5 | { 6 | QApplication a(argc, argv); 7 | 8 | QList list; 9 | for(int j=0; j<10; j++){ 10 | list.append(j); 11 | } 12 | 13 | QList::iterator i; 14 | for(i=list.begin();i!=list.end();++i){ 15 | qDebug() << (*i); 16 | *i = (*i) * 10; 17 | } 18 | 19 | QList::const_iterator ci; 20 | for(ci = list.constBegin();ci!=list.constEnd();++ci){ 21 | qDebug() << (*ci); 22 | } 23 | 24 | return a.exec(); 25 | } 26 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH205/STL_Iterator/STL_Iterator.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp 13 | 14 | HEADERS += 15 | 16 | # Default rules for deployment. 17 | qnx: target.path = /tmp/$${TARGET}/bin 18 | else: unix:!android: target.path = /opt/$${TARGET}/bin 19 | !isEmpty(target.path): INSTALLS += target 20 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH205/STL_Iterator/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | int main(int argc, char *argv[]) 4 | { 5 | QApplication a(argc, argv); 6 | QMap map; 7 | map.insert("abc","123"); 8 | map.insert("def","456"); 9 | map.insert("hij","789"); 10 | 11 | QMap::const_iterator ci; 12 | for(ci=map.constBegin();ci!=map.constEnd();ci++){ 13 | qDebug() << "Key = " << ci.key() << ", Value = " << ci.value(); 14 | } 15 | 16 | QMap::iterator i; 17 | i = map.find("abc"); 18 | if(i!=map.end()){ 19 | i.value() = "000"; 20 | } 21 | qDebug() << "------------"; 22 | QMap::const_iterator ci2; 23 | for(ci2=map.constBegin();ci2!=map.constEnd();ci2++){ 24 | qDebug() << "Key = " << ci2.key() << ", Value = " << ci2.value(); 25 | } 26 | 27 | return a.exec(); 28 | } 29 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH206/myVariant/main.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Widget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH206/myVariant/myVariant.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | widget.cpp 14 | 15 | HEADERS += \ 16 | widget.h 17 | 18 | # Default rules for deployment. 19 | qnx: target.path = /tmp/$${TARGET}/bin 20 | else: unix:!android: target.path = /opt/$${TARGET}/bin 21 | !isEmpty(target.path): INSTALLS += target 22 | -------------------------------------------------------------------------------- /CodeDemo/CH2/CH206/myVariant/widget.cpp: -------------------------------------------------------------------------------- 1 | #include "widget.h" 2 | #include 3 | #include 4 | #include 5 | 6 | Widget::Widget(QWidget *parent) 7 | : QWidget(parent) 8 | { 9 | QVariant v{709}; 10 | qDebug()<map{{"int",709},{"double",3.14}}; 17 | map["string"] = "Hello World"; 18 | map.insert("color",QColor(255,0,0)); 19 | // 调用相应的转换函数 20 | qDebug()<(); // QVariant(QColor, QColor(ARGB 1, 1, 0, 0)) QColor(ARGB 1, 1, 0, 0) 24 | 25 | QStringList sl; 26 | sl << "A" << "B" << "C" << "D"; 27 | QVariant vt{sl}; 28 | 29 | if(vt.type()==QVariant::StringList) { 30 | auto list = vt.toStringList(); 31 | for (int i=0;i 5 | 6 | class Widget : public QWidget 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | Widget(QWidget *parent = nullptr); 12 | ~Widget(); 13 | }; 14 | #endif // WIDGET_H 15 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH301/Splitter/Splitter.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | mainwindow.cpp 14 | 15 | HEADERS += \ 16 | mainwindow.h 17 | 18 | # Default rules for deployment. 19 | qnx: target.path = /tmp/$${TARGET}/bin 20 | else: unix:!android: target.path = /opt/$${TARGET}/bin 21 | !isEmpty(target.path): INSTALLS += target 22 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH301/Splitter/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | QFont font("微软雅黑",15); 10 | a.setFont(font); // 设置字体 11 | 12 | // 主分割窗口 13 | // 新建一个 QSplitter 对象 作为主分割窗口,水平分割窗口 14 | QSplitter *splitterMain = new QSplitter(Qt::Horizontal,nullptr); // 水平布置 15 | 16 | // 新建 一个 QTextEdit 对象 并将其加入 主分割窗口中 17 | QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget"),splitterMain); 18 | // QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget")); 19 | // splitterMain->addWidget(textLeft); 20 | textLeft->setAlignment(Qt::AlignCenter); // 设置 QTextEdit 对齐方式 AlignCenter 居中对齐 21 | 22 | // 右分割窗口 23 | QSplitter *splitterRight = new QSplitter(Qt::Vertical,splitterMain); // 垂直布置 其父窗口为 splitterMain 24 | // QSplitter *splitterRight = new QSplitter(Qt::Vertical); 25 | // splitterRight->setParent(splitterMain); 26 | 27 | // 调用 setOpaqueResize 用于设定分割窗口的分割条在拖拽是是否实时更新显示。 28 | // true 实时显示,false则拖拽时只显示一条灰色的粗线,拖拽到位并释放鼠标后显示分割条。默认 为true 29 | splitterRight->setOpaqueResize(false); 30 | 31 | 32 | QTextEdit *textTop= new QTextEdit(QObject::tr("Top Widget"),splitterRight); 33 | textTop->setAlignment(Qt::AlignCenter); 34 | QTextEdit *textBottom= new QTextEdit(QObject::tr("Bottom Widget"),splitterRight); 35 | textBottom->setAlignment(Qt::AlignCenter); 36 | 37 | splitterMain->setStretchFactor(1,1); 38 | splitterMain->setWindowTitle(QObject::tr("Splitter Test")); 39 | splitterMain->show(); 40 | 41 | // MainWindow w; 42 | // w.show(); 43 | return a.exec(); 44 | } 45 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH301/Splitter/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | 4 | MainWindow::MainWindow(QWidget *parent) 5 | : QMainWindow(parent) 6 | { 7 | } 8 | 9 | MainWindow::~MainWindow() 10 | { 11 | } 12 | 13 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH301/Splitter/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | class MainWindow : public QMainWindow 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | MainWindow(QWidget *parent = nullptr); 12 | ~MainWindow(); 13 | }; 14 | #endif // MAINWINDOW_H 15 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH302/DockWindows/DockWindows.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | dockwindows.cpp 14 | 15 | HEADERS += \ 16 | dockwindows.h 17 | 18 | # Default rules for deployment. 19 | qnx: target.path = /tmp/$${TARGET}/bin 20 | else: unix:!android: target.path = /opt/$${TARGET}/bin 21 | !isEmpty(target.path): INSTALLS += target 22 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH302/DockWindows/dockwindows.cpp: -------------------------------------------------------------------------------- 1 | #include "dockwindows.h" 2 | #include 3 | #include 4 | 5 | DockWindows::DockWindows(QWidget *parent) 6 | : QMainWindow(parent) 7 | { 8 | setWindowTitle(tr("QT基础之停靠窗口QDockWidget类")); 9 | QTextEdit *textEdit = new QTextEdit(this); 10 | textEdit->setText(tr("主窗口")); 11 | textEdit->setAlignment(Qt::AlignCenter); 12 | this->setCentralWidget(textEdit); // 设置 textEdit 为主窗口的中央窗体 13 | 14 | // 停靠窗口1 15 | // 步骤1 创建一个`QDockWidget`对象的停靠窗体 16 | QDockWidget *dock1 = new QDockWidget(tr("停靠窗口1"),this); 17 | // 步骤2 设置此停靠窗体的属性,通常调用 `setFeatures()`以及 `setAllowedAreas()` 18 | dock1->setFeatures(QDockWidget::DockWidgetMovable); // 可移动 19 | dock1->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea); // 可 左侧停靠 和 右侧停靠 20 | // 步骤3 新建一个要插入停靠窗体的控件,比如 `QListWidget`、`QTextEdit` 21 | QTextEdit *textEdit1 = new QTextEdit(this); 22 | textEdit1->setText(tr("停靠窗口1,可移动到左侧停靠和右侧停靠")); 23 | // 步骤4 将控件插入停靠窗体,调用`QDockWidget`的`setWidget()`方法 24 | dock1->setWidget(textEdit1); 25 | // 步骤5 使用 `addDockWidget()`方法在`MainWindow`中加入此停靠窗体 26 | this->addDockWidget(Qt::RightDockWidgetArea,dock1); 27 | 28 | 29 | // 停靠窗口2 30 | // 步骤1 31 | QDockWidget *dock2 = new QDockWidget(tr("停靠窗口2"),this); 32 | // 步骤2 33 | dock2->setFeatures(QDockWidget::DockWidgetClosable|QDockWidget::DockWidgetFloatable); // 可关闭 可浮动 34 | // 步骤3 35 | QTextEdit *textEdit2 = new QTextEdit(this); 36 | textEdit2->setText(tr("停靠窗口2,可关闭 可浮动")); 37 | // 步骤4 38 | dock2->setWidget(textEdit2); 39 | // 步骤5 40 | this->addDockWidget(Qt::RightDockWidgetArea,dock2); 41 | 42 | 43 | // 停靠窗口3 44 | // 步骤1 45 | QDockWidget *dock3 = new QDockWidget(tr("停靠窗口3"),this); 46 | // 步骤2 47 | dock3->setFeatures(QDockWidget::AllDockWidgetFeatures); // 可移动 可关闭 可浮动 48 | // 步骤3 49 | QTextEdit *textEdit3 = new QTextEdit(this); 50 | textEdit3->setText(tr("停靠窗口3,可移动 可关闭 可浮动")); 51 | // 步骤4 52 | dock3->setWidget(textEdit3); 53 | // 步骤5 54 | this->addDockWidget(Qt::RightDockWidgetArea,dock3); 55 | 56 | } 57 | 58 | DockWindows::~DockWindows() 59 | { 60 | } 61 | 62 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH302/DockWindows/dockwindows.h: -------------------------------------------------------------------------------- 1 | #ifndef DOCKWINDOWS_H 2 | #define DOCKWINDOWS_H 3 | 4 | #include 5 | 6 | class DockWindows : public QMainWindow 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | DockWindows(QWidget *parent = nullptr); 12 | ~DockWindows(); 13 | }; 14 | #endif // DOCKWINDOWS_H 15 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH302/DockWindows/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dockwindows.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | DockWindows w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH303/StackDlg/StackDlg.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | dialog.cpp 14 | 15 | HEADERS += \ 16 | dialog.h 17 | 18 | # Default rules for deployment. 19 | qnx: target.path = /tmp/$${TARGET}/bin 20 | else: unix:!android: target.path = /opt/$${TARGET}/bin 21 | !isEmpty(target.path): INSTALLS += target 22 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH303/StackDlg/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include 3 | 4 | Dialog::Dialog(QWidget *parent) 5 | : QDialog(parent) 6 | { 7 | setWindowTitle(tr("QT基础之堆栈窗体QStackedWidget类")); 8 | // 创建 一个 QListWidget 控件对象 ,用于同 QStackedWidget 关联 9 | list = new QListWidget(); 10 | list->addItem(tr("List 1")); 11 | list->addItem(tr("List 2")); 12 | list->addItem(tr("List 3")); 13 | 14 | 15 | // 创建 三个 QLabel 标签控件对象,作为堆栈窗口需要显示的三层窗体 16 | label1 = new QLabel(tr("WindowTest1")); 17 | label2 = new QLabel(tr("WindowTest2")); 18 | label3 = new QLabel(tr("WindowTest3")); 19 | 20 | // 创建 QStackedWidget 堆栈窗体对象 21 | stackedWidget = new QStackedWidget(this); 22 | // 将 三个 QLabel 标签控件对象 插入 QStackedWidget 23 | stackedWidget->addWidget(label1); 24 | stackedWidget->addWidget(label2); 25 | stackedWidget->addWidget(label3); 26 | // 创建 布局 27 | QHBoxLayout *layout = new QHBoxLayout(this);// 水平布局 28 | 29 | layout->setMargin(5); // 对话框或窗体 边距 5 30 | layout->setSpacing(5); // 各个控件之间的间距 5 31 | layout->addWidget(list); 32 | layout->addWidget(stackedWidget,5,Qt::AlignCenter); 33 | layout->setStretchFactor(list,1); // 设定可伸缩控件 34 | layout->setStretchFactor(stackedWidget,3); 35 | connect(list, SIGNAL(currentRowChanged(int)),stackedWidget, SLOT(setCurrentIndex(int))); 36 | 37 | 38 | } 39 | 40 | Dialog::~Dialog() 41 | { 42 | } 43 | 44 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH303/StackDlg/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Dialog : public QDialog 11 | { 12 | Q_OBJECT 13 | 14 | public: 15 | Dialog(QWidget *parent = nullptr); 16 | ~Dialog(); 17 | private: 18 | QListWidget *list; 19 | QComboBox *comboBox; 20 | QStackedWidget *stackedWidget; 21 | QLabel *label1; 22 | QLabel *label2; 23 | QLabel *label3; 24 | }; 25 | #endif // DIALOG_H 26 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH303/StackDlg/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Dialog w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH304/UserInfo/UserInfo.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # You can make your code fail to compile if it uses deprecated APIs. 8 | # In order to do so, uncomment the following line. 9 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 10 | 11 | SOURCES += \ 12 | main.cpp \ 13 | dialog.cpp 14 | 15 | HEADERS += \ 16 | dialog.h 17 | 18 | # Default rules for deployment. 19 | qnx: target.path = /tmp/$${TARGET}/bin 20 | else: unix:!android: target.path = /opt/$${TARGET}/bin 21 | !isEmpty(target.path): INSTALLS += target 22 | 23 | RESOURCES += \ 24 | head.qrc 25 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH304/UserInfo/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include 3 | 4 | Dialog::Dialog(QWidget *parent) 5 | : QDialog(parent) 6 | { 7 | setWindowTitle(tr("QT基础之基本布局QLayout")); 8 | LeftLayoutSetting(); 9 | RightLayoutSetting(); 10 | BottomLayoutSetting(); 11 | MainLayoutSetting(); 12 | } 13 | 14 | Dialog::~Dialog() 15 | { 16 | } 17 | 18 | void Dialog::LeftLayoutSetting() 19 | { 20 | //左侧 21 | UserNameLabel = new QLabel(tr("用户名:")); 22 | UserNameLineEdit = new QLineEdit(); 23 | 24 | NameLabel = new QLabel(tr("姓名:")); 25 | NameLineEdit = new QLineEdit(); 26 | 27 | SexLabel = new QLabel(tr("性别:")); 28 | SexComboBox = new QComboBox(); 29 | SexComboBox->addItem(tr("女")); 30 | SexComboBox->addItem(tr("男")); 31 | 32 | DepartmentLabel = new QLabel(tr("部门:")); 33 | DepartmentTextEdit = new QTextEdit(); 34 | 35 | AgeLabel = new QLabel(tr("年龄:")); 36 | AgeLineEdit = new QLineEdit(); 37 | 38 | NoteLabel = new QLabel(tr("备注:")); 39 | // 设置控件的风格,有形状和阴影两项配合设定 40 | // 形状: NoFrame Box Panel WinPanel HLine VLine StyledPanel 六种 41 | // 阴影: Plain Raised Sunken 三种 42 | NoteLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); 43 | 44 | LeftLayout = new QGridLayout(); // 由于 不是主布局器 不用指定父窗口 45 | 46 | LeftLayout->addWidget(UserNameLabel,0,0); 47 | LeftLayout->addWidget(UserNameLineEdit,0,1); 48 | 49 | LeftLayout->addWidget(NameLabel,1,0); 50 | LeftLayout->addWidget(NameLineEdit,1,1); 51 | 52 | LeftLayout->addWidget(SexLabel,2,0); 53 | LeftLayout->addWidget(SexComboBox,2,1); 54 | 55 | LeftLayout->addWidget(DepartmentLabel,3,0); 56 | LeftLayout->addWidget(DepartmentTextEdit,3,1); 57 | 58 | LeftLayout->addWidget(AgeLabel,4,0); 59 | LeftLayout->addWidget(AgeLineEdit,4,1); 60 | 61 | LeftLayout->addWidget(NoteLabel,5,0,1,2); 62 | // 设置 列的 拉伸系数,对话框框架大小改变,两列的比例不变 这里 1:3 63 | LeftLayout->setColumnStretch(0,1); 64 | LeftLayout->setColumnStretch(1,3); 65 | } 66 | void Dialog::RightLayoutSetting() 67 | { 68 | HeadLabel = new QLabel(tr("头像")); 69 | HeadIconLabel = new QLabel(); 70 | QPixmap icon(":/icon/head.png"); 71 | HeadIconLabel->setPixmap(icon); 72 | HeadIconLabel->setFixedSize(100, 100); 73 | //HeadIconLabel->resize(icon.width(),icon.height()); 74 | // setScaledContents按比例缩放图片达到理想的效果 75 | HeadIconLabel->setScaledContents(true); 76 | UpdateHeadBtn = new QPushButton(tr("更新")); 77 | // 右上 头像部分布局 78 | RightTopLayout = new QHBoxLayout(); 79 | RightTopLayout->addWidget(HeadLabel); 80 | RightTopLayout->addWidget(HeadIconLabel); 81 | RightTopLayout->addWidget(UpdateHeadBtn); 82 | RightTopLayout->setSpacing(20); // 控件之间的间距 83 | 84 | PersonalInfoLabel = new QLabel(tr("个人说明")); 85 | PersonalInfoTextEdit = new QTextEdit(); 86 | 87 | RightLayout = new QVBoxLayout(); // 由于 不是主布局器 不用指定父窗口 88 | 89 | RightLayout->addLayout(RightTopLayout); // 子布局 90 | RightLayout->addWidget(PersonalInfoLabel); 91 | RightLayout->addWidget(PersonalInfoTextEdit); 92 | RightLayout->setMargin(10); // 控件与窗体的边距 93 | 94 | } 95 | 96 | void Dialog::BottomLayoutSetting() 97 | { 98 | OkBtn = new QPushButton(tr("确定")); 99 | CancelBtn = new QPushButton(tr("取消")); 100 | BottomLayout = new QHBoxLayout(); 101 | // 之前(这里是左边) 加入 空间间隔 占位符,使两个按钮靠右对齐 102 | BottomLayout->addStretch(); 103 | BottomLayout->addWidget(OkBtn); 104 | BottomLayout->addWidget(CancelBtn); 105 | 106 | } 107 | 108 | void Dialog::MainLayoutSetting() 109 | { 110 | MainLayout = new QGridLayout(this);// 主布局 父窗口指定为this 111 | MainLayout->setMargin(15); // 控件与窗体的边距 112 | MainLayout->setSpacing(10); // 控件之间的间距 113 | MainLayout->addLayout(LeftLayout,0,0); 114 | MainLayout->addLayout(RightLayout,0,1); 115 | MainLayout->addLayout(BottomLayout,1,0,1,2); // 占两列 116 | 117 | // 设置 最优化显示,使用户无法改变对话框大小,最优化就是控件按其 sizeHint 的大小显示 118 | MainLayout->setSizeConstraint(QLayout::SetFixedSize); 119 | } 120 | 121 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH304/UserInfo/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class Dialog : public QDialog 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | Dialog(QWidget *parent = nullptr); 18 | ~Dialog(); 19 | private: 20 | // LeftLayout 设置函数 21 | void LeftLayoutSetting(); 22 | // RightLayout 设置函数 23 | void RightLayoutSetting(); 24 | // BottomLayout 设置函数 25 | void BottomLayoutSetting(); 26 | // MainLayout 设置函数 27 | void MainLayoutSetting(); 28 | 29 | // LeftLayout 30 | QLabel *UserNameLabel;// 用户名 31 | QLabel *NameLabel;// 姓名 32 | QLabel *SexLabel;// 性别 33 | QLabel *DepartmentLabel;// 部门 34 | QLabel *AgeLabel;// 年龄 35 | QLabel *NoteLabel;// 备注 36 | QLineEdit * UserNameLineEdit; 37 | QLineEdit *NameLineEdit; 38 | QComboBox *SexComboBox; 39 | QTextEdit *DepartmentTextEdit; 40 | QLineEdit *AgeLineEdit; 41 | QGridLayout *LeftLayout; //整个 左侧 网格布局 42 | 43 | // RightLayout 44 | QLabel *HeadLabel; // 头像 45 | QLabel *HeadIconLabel; // 头像图标 46 | QPushButton *UpdateHeadBtn; // 头像更新按钮 47 | QHBoxLayout *RightTopLayout; // 头像 这部分 水平布局 48 | QLabel *PersonalInfoLabel; // 个人说明 49 | QTextEdit *PersonalInfoTextEdit; 50 | QVBoxLayout *RightLayout; //整个 右侧 垂直布局 51 | 52 | // BottomLayout 53 | QPushButton *OkBtn; // 确定 按钮 54 | QPushButton *CancelBtn; // 取消 按钮 55 | QHBoxLayout *BottomLayout; //整个 底部侧 水平布局 56 | 57 | // MainLayout 58 | QGridLayout *MainLayout; //整个 所有 网格布局 59 | }; 60 | #endif // DIALOG_H 61 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH304/UserInfo/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH3/CH304/UserInfo/head.png -------------------------------------------------------------------------------- /CodeDemo/CH3/CH304/UserInfo/head.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | head.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH304/UserInfo/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Dialog w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/LayoutExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | baseinfo.cpp \ 20 | contact.cpp \ 21 | detail.cpp \ 22 | main.cpp \ 23 | content.cpp 24 | 25 | HEADERS += \ 26 | baseinfo.h \ 27 | contact.h \ 28 | content.h \ 29 | detail.h 30 | 31 | # Default rules for deployment. 32 | qnx: target.path = /tmp/$${TARGET}/bin 33 | else: unix:!android: target.path = /opt/$${TARGET}/bin 34 | !isEmpty(target.path): INSTALLS += target 35 | 36 | RESOURCES += \ 37 | sorces.qrc 38 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/baseinfo.cpp: -------------------------------------------------------------------------------- 1 | #include "baseinfo.h" 2 | 3 | BaseInfo::BaseInfo(QWidget *parent) : QWidget(parent) 4 | { 5 | setWindowTitle(tr("QT基础之基本布局QLayout")); 6 | LeftLayoutSetting(); 7 | RightLayoutSetting(); 8 | MainLayoutSetting(); 9 | } 10 | 11 | 12 | void BaseInfo::LeftLayoutSetting() 13 | { 14 | //左侧 15 | UserNameLabel = new QLabel(tr("用户名:")); 16 | UserNameLineEdit = new QLineEdit(); 17 | 18 | NameLabel = new QLabel(tr("姓名:")); 19 | NameLineEdit = new QLineEdit(); 20 | 21 | SexLabel = new QLabel(tr("性别:")); 22 | SexComboBox = new QComboBox(); 23 | SexComboBox->addItem(tr("女")); 24 | SexComboBox->addItem(tr("男")); 25 | 26 | DepartmentLabel = new QLabel(tr("部门:")); 27 | DepartmentTextEdit = new QTextEdit(); 28 | 29 | AgeLabel = new QLabel(tr("年龄:")); 30 | AgeLineEdit = new QLineEdit(); 31 | 32 | NoteLabel = new QLabel(tr("备注:")); 33 | // 设置控件的风格,有形状和阴影两项配合设定 34 | // 形状: NoFrame Box Panel WinPanel HLine VLine StyledPanel 六种 35 | // 阴影: Plain Raised Sunken 三种 36 | NoteLabel->setFrameStyle(QFrame::Panel|QFrame::Sunken); 37 | 38 | LeftLayout = new QGridLayout(); // 由于 不是主布局器 不用指定父窗口 39 | 40 | LeftLayout->addWidget(UserNameLabel,0,0); 41 | LeftLayout->addWidget(UserNameLineEdit,0,1); 42 | 43 | LeftLayout->addWidget(NameLabel,1,0); 44 | LeftLayout->addWidget(NameLineEdit,1,1); 45 | 46 | LeftLayout->addWidget(SexLabel,2,0); 47 | LeftLayout->addWidget(SexComboBox,2,1); 48 | 49 | LeftLayout->addWidget(DepartmentLabel,3,0); 50 | LeftLayout->addWidget(DepartmentTextEdit,3,1); 51 | 52 | LeftLayout->addWidget(AgeLabel,4,0); 53 | LeftLayout->addWidget(AgeLineEdit,4,1); 54 | 55 | LeftLayout->addWidget(NoteLabel,5,0,1,2); 56 | // 设置 列的 拉伸系数,对话框框架大小改变,两列的比例不变 这里 1:3 57 | LeftLayout->setColumnStretch(0,1); 58 | LeftLayout->setColumnStretch(1,3); 59 | } 60 | void BaseInfo::RightLayoutSetting() 61 | { 62 | HeadLabel = new QLabel(tr("头像")); 63 | HeadIconLabel = new QLabel(); 64 | QPixmap icon(":/icon/head.png"); 65 | HeadIconLabel->setPixmap(icon); 66 | HeadIconLabel->setFixedSize(100, 100); 67 | //HeadIconLabel->resize(icon.width(),icon.height()); 68 | // setScaledContents按比例缩放图片达到理想的效果 69 | HeadIconLabel->setScaledContents(true); 70 | UpdateHeadBtn = new QPushButton(tr("更新")); 71 | // 右上 头像部分布局 72 | RightTopLayout = new QHBoxLayout(); 73 | RightTopLayout->addWidget(HeadLabel); 74 | RightTopLayout->addWidget(HeadIconLabel); 75 | RightTopLayout->addWidget(UpdateHeadBtn); 76 | RightTopLayout->setSpacing(20); // 控件之间的间距 77 | 78 | PersonalInfoLabel = new QLabel(tr("个人说明")); 79 | PersonalInfoTextEdit = new QTextEdit(); 80 | 81 | RightLayout = new QVBoxLayout(); // 由于 不是主布局器 不用指定父窗口 82 | 83 | RightLayout->addLayout(RightTopLayout); // 子布局 84 | RightLayout->addWidget(PersonalInfoLabel); 85 | RightLayout->addWidget(PersonalInfoTextEdit); 86 | RightLayout->setMargin(10); // 控件与窗体的边距 87 | 88 | } 89 | 90 | void BaseInfo::MainLayoutSetting() 91 | { 92 | MainLayout = new QGridLayout(this);// 主布局 父窗口指定为this 93 | MainLayout->setMargin(15); // 控件与窗体的边距 94 | MainLayout->setSpacing(10); // 控件之间的间距 95 | MainLayout->addLayout(LeftLayout,0,0); 96 | MainLayout->addLayout(RightLayout,0,1); 97 | 98 | MainLayout->setSizeConstraint(QLayout::SetFixedSize); 99 | } 100 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/baseinfo.h: -------------------------------------------------------------------------------- 1 | #ifndef BASEINFO_H 2 | #define BASEINFO_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | class BaseInfo : public QWidget 13 | { 14 | Q_OBJECT 15 | public: 16 | explicit BaseInfo(QWidget *parent = nullptr); 17 | 18 | signals: 19 | 20 | private: 21 | // LeftLayout 设置函数 22 | void LeftLayoutSetting(); 23 | // RightLayout 设置函数 24 | void RightLayoutSetting(); 25 | // MainLayout 设置函数 26 | void MainLayoutSetting(); 27 | 28 | // LeftLayout 29 | QLabel *UserNameLabel;// 用户名 30 | QLabel *NameLabel;// 姓名 31 | QLabel *SexLabel;// 性别 32 | QLabel *DepartmentLabel;// 部门 33 | QLabel *AgeLabel;// 年龄 34 | QLabel *NoteLabel;// 备注 35 | QLineEdit * UserNameLineEdit; 36 | QLineEdit *NameLineEdit; 37 | QComboBox *SexComboBox; 38 | QTextEdit *DepartmentTextEdit; 39 | QLineEdit *AgeLineEdit; 40 | QGridLayout *LeftLayout; //整个 左侧 网格布局 41 | 42 | // RightLayout 43 | QLabel *HeadLabel; // 头像 44 | QLabel *HeadIconLabel; // 头像图标 45 | QPushButton *UpdateHeadBtn; // 头像更新按钮 46 | QHBoxLayout *RightTopLayout; // 头像 这部分 水平布局 47 | QLabel *PersonalInfoLabel; // 个人说明 48 | QTextEdit *PersonalInfoTextEdit; 49 | QVBoxLayout *RightLayout; //整个 右侧 垂直布局 50 | 51 | // MainLayout 52 | QGridLayout *MainLayout; //整个 所有 网格布局 53 | }; 54 | 55 | #endif // BASEINFO_H 56 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/contact.cpp: -------------------------------------------------------------------------------- 1 | #include "contact.h" 2 | 3 | Contact::Contact(QWidget *parent) : QWidget(parent) 4 | { 5 | emailLabel = new QLabel(tr("电子邮件:")); 6 | emailLineEdit = new QLineEdit; 7 | addrLabel = new QLabel(tr("联系地址:")); 8 | addrLineEdit = new QLineEdit; 9 | zipCodeLabel = new QLabel(tr("邮政编码:")); 10 | zipCodeLineEdit = new QLineEdit; 11 | mobileTeleLabel = new QLabel(tr("移动电话:")); 12 | mobileTeleLineEdit = new QLineEdit; 13 | mobileTeleCheckBox = new QCheckBox(tr("接收短信")); 14 | officePhoneLabel = new QLabel(tr("办公电话:")); 15 | officePhoneEdit = new QLineEdit; 16 | 17 | mainLayout = new QGridLayout(this); 18 | mainLayout->setMargin(15); 19 | mainLayout->setSpacing(10); 20 | mainLayout->addWidget(emailLabel,0,0); 21 | mainLayout->addWidget(emailLineEdit,0,1); 22 | mainLayout->addWidget(addrLabel,1,0); 23 | mainLayout->addWidget(addrLineEdit,1,1); 24 | mainLayout->addWidget(zipCodeLabel,2,0); 25 | mainLayout->addWidget(zipCodeLineEdit,2,1); 26 | mainLayout->addWidget(mobileTeleLabel,3,0); 27 | mainLayout->addWidget(mobileTeleLineEdit,3,1); 28 | mainLayout->addWidget(mobileTeleCheckBox,3,2); 29 | mainLayout->addWidget(officePhoneLabel,4,0); 30 | mainLayout->addWidget(officePhoneEdit,4,1); 31 | // 保存布局的调整大小模式 32 | mainLayout->setSizeConstraint(QLayout::SetFixedSize); 33 | } 34 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/contact.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTACT_H 2 | #define CONTACT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | class Contact : public QWidget 11 | { 12 | Q_OBJECT 13 | public: 14 | explicit Contact(QWidget *parent = nullptr); 15 | 16 | signals: 17 | 18 | private: 19 | QLabel *emailLabel; 20 | QLineEdit *emailLineEdit; 21 | QLabel *addrLabel; 22 | QLineEdit *addrLineEdit; 23 | QLabel *zipCodeLabel; 24 | QLineEdit *zipCodeLineEdit; 25 | QLabel *mobileTeleLabel; 26 | QLineEdit *mobileTeleLineEdit; 27 | QCheckBox *mobileTeleCheckBox; 28 | QLabel *officePhoneLabel; 29 | QLineEdit *officePhoneEdit; 30 | 31 | QGridLayout *mainLayout; 32 | }; 33 | 34 | #endif // CONTACT_H 35 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/content.cpp: -------------------------------------------------------------------------------- 1 | #include "content.h" 2 | #include 3 | #include 4 | 5 | Content::Content(QWidget *parent) 6 | : QFrame(parent) 7 | { 8 | // 创建 QStackedWidget 9 | stack = new QStackedWidget(this); 10 | stack->setFrameStyle(QFrame::Panel|QFrame::Raised); // 设置风格 11 | // 向QStackedWidget中插入页面,按顺序插入 12 | baseInfo = new BaseInfo(); 13 | contact = new Contact(); 14 | detail = new Detail(); 15 | stack->addWidget(baseInfo); 16 | stack->addWidget(contact); 17 | stack->addWidget(detail); 18 | // 创建两按钮 19 | modifyBtn = new QPushButton(tr("修改")); 20 | closeBtn = new QPushButton(tr("关闭")); 21 | // 按钮布局 22 | btnLayout = new QHBoxLayout; 23 | // 加入 空间间隔 占位符,使两个按钮靠右对齐 24 | btnLayout->addStretch(); 25 | btnLayout->addWidget(modifyBtn); 26 | btnLayout->addWidget(closeBtn); 27 | // 整体布局 28 | rightMainLayout = new QVBoxLayout(this); 29 | rightMainLayout->setMargin(10); 30 | rightMainLayout->setSpacing(6); 31 | rightMainLayout->addWidget(stack); 32 | rightMainLayout->addLayout(btnLayout); 33 | 34 | connect(modifyBtn,SIGNAL(clicked()),this,SLOT(modifyBtnClicked())); 35 | connect(closeBtn,SIGNAL(clicked()),this,SLOT(closeBtnClicked())); 36 | } 37 | 38 | Content::~Content() 39 | { 40 | } 41 | 42 | void Content::modifyBtnClicked() 43 | { 44 | qDebug() << "modifyBtnClicked"; 45 | } 46 | 47 | void Content::closeBtnClicked() 48 | { 49 | qDebug() << "closeBtnClicked"; 50 | QApplication::instance()->exit(); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/content.h: -------------------------------------------------------------------------------- 1 | #ifndef CONTENT_H 2 | #define CONTENT_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "baseinfo.h" 11 | #include "contact.h" 12 | #include "detail.h" 13 | 14 | class Content : public QFrame 15 | { 16 | Q_OBJECT 17 | // 包含 三个页面对象、两个按钮,一个堆栈窗体对象 18 | public: 19 | Content(QWidget *parent = nullptr); 20 | ~Content(); 21 | // 一个堆栈窗体对象 22 | QStackedWidget *stack; 23 | private slots: 24 | void modifyBtnClicked(); 25 | void closeBtnClicked(); 26 | private: 27 | // 整体布局 28 | QVBoxLayout *rightMainLayout; 29 | // 三个页面对象 30 | BaseInfo *baseInfo; 31 | Contact *contact; 32 | Detail *detail; 33 | // 两个按钮 34 | QPushButton *modifyBtn; 35 | QPushButton *closeBtn; 36 | QHBoxLayout *btnLayout; // 按钮布局 37 | }; 38 | #endif // CONTENT_H 39 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/detail.cpp: -------------------------------------------------------------------------------- 1 | #include "detail.h" 2 | 3 | Detail::Detail(QWidget *parent) : QWidget(parent) 4 | { 5 | nationalLabel = new QLabel(tr("国家/地址:")); 6 | nationalComboBox = new QComboBox; 7 | nationalComboBox->insertItem(0,tr("国家1")); 8 | nationalComboBox->insertItem(1,tr("国家2")); 9 | nationalComboBox->insertItem(2,tr("国家3")); 10 | 11 | provinceLabel = new QLabel(tr("省份:")); 12 | provinceComboBox = new QComboBox; 13 | provinceComboBox->insertItem(0,tr("省份1")); 14 | provinceComboBox->insertItem(1,tr("省份2")); 15 | provinceComboBox->insertItem(2,tr("省份3")); 16 | 17 | cityLabel = new QLabel(tr("城市:")); 18 | cityLineEdit = new QLineEdit; 19 | 20 | introductLabel = new QLabel(tr("个人说明:")); 21 | introductLineEdit = new QTextEdit; 22 | 23 | mainLayout = new QGridLayout(this); 24 | mainLayout->addWidget(nationalLabel,0,0); 25 | mainLayout->addWidget(nationalComboBox,0,1); 26 | mainLayout->addWidget(provinceLabel,1,0); 27 | mainLayout->addWidget(provinceComboBox,1,1); 28 | mainLayout->addWidget(cityLabel,2,0); 29 | mainLayout->addWidget(cityLineEdit,2,1); 30 | mainLayout->addWidget(introductLabel,3,0); 31 | mainLayout->addWidget(introductLineEdit,3,1); 32 | } 33 | 34 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/detail.h: -------------------------------------------------------------------------------- 1 | #ifndef DETAIL_H 2 | #define DETAIL_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class Detail : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit Detail(QWidget *parent = nullptr); 16 | 17 | signals: 18 | 19 | private: 20 | QLabel *nationalLabel; 21 | QComboBox *nationalComboBox; 22 | QLabel *provinceLabel; 23 | QComboBox *provinceComboBox; 24 | QLabel *cityLabel; 25 | QLineEdit *cityLineEdit; 26 | QLabel *introductLabel; 27 | QTextEdit *introductLineEdit; 28 | 29 | QGridLayout *mainLayout; 30 | }; 31 | 32 | #endif // DETAIL_H 33 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/head.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH3/CH305/LayoutExample/head.png -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "content.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | int main(int argc, char *argv[]) 9 | { 10 | QApplication a(argc, argv); 11 | // 设置字体 12 | QFont font("微软雅黑",12); 13 | a.setFont(font); 14 | // 分割窗体 15 | QSplitter *splitter = new QSplitter(Qt::Horizontal); 16 | splitter->setOpaqueResize(true); // 拖拉分割线的时候,窗口是否实时显示 17 | QListWidget *list = new QListWidget; 18 | splitter->addWidget(list); 19 | list->insertItem(0,QObject::tr("基本信息")); 20 | list->insertItem(1,QObject::tr("联系方式")); 21 | list->insertItem(2,QObject::tr("详细资料")); 22 | Content *content= new Content(); 23 | splitter->addWidget(content); 24 | QObject::connect(list,SIGNAL(currentRowChanged(int)),content->stack, 25 | SLOT(setCurrentIndex(int))); 26 | 27 | splitter->setWindowTitle(QObject::tr("资料修改")); 28 | splitter->setMinimumSize(splitter->minimumSize()); 29 | splitter->setMaximumSize(splitter->maximumSize()); 30 | splitter->show(); 31 | 32 | // Content w; 33 | // w.show(); 34 | return a.exec(); 35 | } 36 | -------------------------------------------------------------------------------- /CodeDemo/CH3/CH305/LayoutExample/sorces.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | head.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/DialogExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | inputdlg.cpp \ 20 | main.cpp \ 21 | dialog.cpp \ 22 | msgboxdlg.cpp 23 | 24 | HEADERS += \ 25 | dialog.h \ 26 | inputdlg.h \ 27 | msgboxdlg.h 28 | 29 | # Default rules for deployment. 30 | qnx: target.path = /tmp/$${TARGET}/bin 31 | else: unix:!android: target.path = /opt/$${TARGET}/bin 32 | !isEmpty(target.path): INSTALLS += target 33 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/dialog.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | #include 3 | Dialog::Dialog(QWidget *parent) 4 | : QDialog(parent) 5 | { 6 | setWindowTitle(tr("各种标准对话框的实例")); 7 | mainLayOut = new QGridLayout(this); // 创建布局 8 | createQFileDialog(); // 标注文件对话框 相关创建 9 | createQColorDialog(); // 标注颜色对话框 相关创建 10 | createQFontDialog(); // 标准字体对话框 相关创建 11 | createQInputDialog(); // 标准输入对话框 12 | createQMessageDialog(); // 消息框 13 | createCustomDialog(); // 自定义消息框 14 | } 15 | 16 | Dialog::~Dialog() 17 | { 18 | } 19 | 20 | void Dialog::showFile() 21 | { 22 | QString str = QFileDialog::getOpenFileName(this,"Open file dialog","D:\\", 23 | tr("C++ files(*.cpp);;C files(*.c);;Head files(*.h)")); 24 | fileLineEdit->setText(str); 25 | } 26 | 27 | void Dialog::showColor() 28 | { 29 | QColor color = QColorDialog::getColor(Qt::blue); 30 | if(color.isValid()){ 31 | colorFrame->setPalette(QPalette(color)); 32 | } 33 | } 34 | 35 | void Dialog::showFont() 36 | { 37 | bool isOK = false; 38 | QFont font = QFontDialog::getFont(&isOK); 39 | if(isOK){ 40 | fontLineEdit->setFont(font); 41 | } 42 | } 43 | 44 | void Dialog::showInputDlg() 45 | { 46 | inputDlg = new InputDlg(this); 47 | inputDlg->show(); 48 | } 49 | 50 | void Dialog::showMsgDlg() 51 | { 52 | msgDlg = new MsgBoxDlg(this); 53 | msgDlg->show(); 54 | } 55 | 56 | void Dialog::showCustomDlg() 57 | { 58 | label->setText(tr("Custom Message Box")); 59 | QMessageBox customMsgBox; 60 | customMsgBox.setWindowTitle(tr("用户自定义消息框")); 61 | QPushButton *yesBtn = customMsgBox.addButton(tr("Yes"),QMessageBox::ActionRole); // 自定义按钮,参数为 按钮显示文字,按钮类型 62 | QPushButton *noBtn = customMsgBox.addButton(tr("no"),QMessageBox::ActionRole); 63 | QPushButton *cancelBtn = customMsgBox.addButton(QMessageBox::Cancel); // 加入 标准按钮, 按addButton顺序从左到右依次加入 64 | customMsgBox.setText(tr("这是一个用户自定义消息框")); 65 | // customMsgBox.setIconPixmap(QPixmap("xx.png")); // 自定义图标 66 | customMsgBox.exec(); 67 | auto ret = customMsgBox.clickedButton(); 68 | if(ret == yesBtn){ 69 | label->setText(tr("Custom Message Box/Yes")); 70 | } 71 | if(ret == noBtn){ 72 | label->setText(tr("Custom Message Box/No")); 73 | } 74 | if(ret == cancelBtn){ 75 | label->setText(tr("Custom Message Box/Cancel")); 76 | } 77 | return; 78 | } 79 | 80 | void Dialog::createQFileDialog() 81 | { 82 | // 创建组件 83 | fileBtn = new QPushButton; 84 | fileBtn->setText(tr("标准文件对话框实例")); 85 | fileLineEdit = new QLineEdit; 86 | 87 | // 布局 88 | mainLayOut->addWidget(fileBtn,0,0); 89 | mainLayOut->addWidget(fileLineEdit,0,1); 90 | 91 | // 关联事件 92 | connect(fileBtn,SIGNAL(clicked()),this,SLOT(showFile())); 93 | } 94 | 95 | void Dialog::createQColorDialog() 96 | { 97 | colorBtn = new QPushButton; 98 | colorBtn->setText(tr("标准颜色对话框实例")); 99 | colorFrame = new QFrame; 100 | colorFrame->setFrameShape(QFrame::Box); 101 | colorFrame->setAutoFillBackground(true); 102 | 103 | mainLayOut->addWidget(colorBtn,1,0); 104 | mainLayOut->addWidget(colorFrame,1,1); 105 | 106 | connect(colorBtn,SIGNAL(clicked()),this,SLOT(showColor())); 107 | } 108 | 109 | void Dialog::createQFontDialog() 110 | { 111 | fontBtn = new QPushButton; 112 | fontBtn->setText(tr("标准字体对话框实例")); 113 | fontLineEdit = new QLineEdit; 114 | fontLineEdit->setText(tr("Welcome")); 115 | 116 | mainLayOut->addWidget(fontBtn,2,0); 117 | mainLayOut->addWidget(fontLineEdit,2,1); 118 | 119 | connect(fontBtn,SIGNAL(clicked()),this,SLOT(showFont())); 120 | } 121 | 122 | void Dialog::createQInputDialog() 123 | { 124 | inputBtn = new QPushButton; 125 | inputBtn->setText(tr("标准输入对话框实例")); 126 | 127 | mainLayOut->addWidget(inputBtn,3,0); 128 | connect(inputBtn,SIGNAL(clicked()),this,SLOT(showInputDlg())); 129 | } 130 | 131 | void Dialog::createQMessageDialog() 132 | { 133 | msgBtn = new QPushButton; 134 | msgBtn->setText(tr("标准消息对话框实例")); 135 | 136 | mainLayOut->addWidget(msgBtn,3,1); 137 | connect(msgBtn,SIGNAL(clicked()),this,SLOT(showMsgDlg())); 138 | } 139 | 140 | void Dialog::createCustomDialog() 141 | { 142 | customBtn = new QPushButton; 143 | customBtn->setText(tr("用户自定义消息对话框实例")); 144 | label = new QLabel; 145 | label->setFrameStyle(QFrame::Panel|QFrame::Sunken); 146 | 147 | mainLayOut->addWidget(customBtn,4,0); 148 | mainLayOut->addWidget(label,4,1); 149 | connect(customBtn,SIGNAL(clicked()),this,SLOT(showCustomDlg())); 150 | } 151 | 152 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/dialog.h: -------------------------------------------------------------------------------- 1 | #ifndef DIALOG_H 2 | #define DIALOG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | 14 | #include "inputdlg.h" 15 | #include "msgboxdlg.h" 16 | 17 | class Dialog : public QDialog 18 | { 19 | Q_OBJECT 20 | 21 | public: 22 | Dialog(QWidget *parent = nullptr); 23 | ~Dialog(); 24 | 25 | private slots: 26 | void showFile(); // fileBtn 点击触发 27 | void showColor(); // colorBtn 28 | void showFont(); // fontBtn 29 | void showInputDlg(); // inputBtn 30 | void showMsgDlg(); // msgBtn 31 | void showCustomDlg(); // customBtn 32 | private: 33 | QGridLayout *mainLayOut; // 网格布局布局 34 | 35 | // 标准文件对话框成员变量 36 | QPushButton *fileBtn; // 点击按钮弹出 标准文件对话框 37 | QLineEdit *fileLineEdit; // 显示标准对话框选择的文件 38 | 39 | // 标准颜色对话框成员变量 40 | QPushButton *colorBtn; 41 | QFrame *colorFrame; // 显示选择的颜色 42 | 43 | // 标准字体对话框成员变量 44 | QPushButton *fontBtn; 45 | QLineEdit *fontLineEdit; 46 | 47 | // 标准输入对话框 48 | QPushButton *inputBtn; 49 | InputDlg *inputDlg; 50 | 51 | //消息对话框 52 | QPushButton *msgBtn; 53 | MsgBoxDlg *msgDlg; 54 | 55 | // 自定义消息框 56 | QPushButton *customBtn; 57 | QLabel *label; 58 | private: 59 | void createQFileDialog(); 60 | void createQColorDialog(); 61 | void createQFontDialog(); 62 | void createQInputDialog(); 63 | void createQMessageDialog(); 64 | void createCustomDialog(); 65 | }; 66 | #endif // DIALOG_H 67 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/inputdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "inputdlg.h" 2 | 3 | #include 4 | 5 | InputDlg::InputDlg(QWidget *parent) 6 | :QDialog(parent) 7 | { 8 | setWindowTitle(tr("标准输入对话框实例")); 9 | 10 | nameLabel1 = new QLabel; 11 | nameLabel1->setText(tr("姓名:")); 12 | nameLabel2 = new QLabel; 13 | nameLabel2->setText(tr("李四")); 14 | nameLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken); 15 | nameBtn = new QPushButton; 16 | nameBtn->setText(tr("修改姓名")); 17 | 18 | sexLabel1 = new QLabel; 19 | sexLabel1->setText(tr("性别:")); 20 | sexLabel2 = new QLabel; 21 | sexLabel2->setText(tr("男")); 22 | sexLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken); 23 | sexBtn = new QPushButton; 24 | sexBtn->setText(tr("修改性别")); 25 | 26 | ageLabel1 = new QLabel; 27 | ageLabel1->setText(tr("年龄:")); 28 | ageLabel2 = new QLabel; 29 | ageLabel2->setText(tr("21")); 30 | ageLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken); 31 | ageBtn = new QPushButton; 32 | ageBtn->setText(tr("修改年龄")); 33 | 34 | scoreLabel1 = new QLabel; 35 | scoreLabel1->setText(tr("分数:")); 36 | scoreLabel2 = new QLabel; 37 | scoreLabel2->setText(tr("89")); 38 | scoreLabel2->setFrameStyle(QFrame::Panel|QFrame::Sunken); 39 | scoreBtn = new QPushButton; 40 | scoreBtn->setText(tr("修改分数")); 41 | 42 | mainLayout = new QGridLayout(this); 43 | mainLayout->addWidget(nameLabel1,0,0); 44 | mainLayout->addWidget(nameLabel2,0,1); 45 | mainLayout->addWidget(nameBtn,0,2); 46 | 47 | mainLayout->addWidget(sexLabel1,1,0); 48 | mainLayout->addWidget(sexLabel2,1,1); 49 | mainLayout->addWidget(sexBtn,1,2); 50 | 51 | mainLayout->addWidget(ageLabel1,2,0); 52 | mainLayout->addWidget(ageLabel2,2,1); 53 | mainLayout->addWidget(ageBtn,2,2); 54 | 55 | mainLayout->addWidget(scoreLabel1,3,0); 56 | mainLayout->addWidget(scoreLabel2,3,1); 57 | mainLayout->addWidget(scoreBtn,3,2); 58 | mainLayout->setSpacing(10); 59 | mainLayout->setMargin(15); 60 | 61 | connect(nameBtn,SIGNAL(clicked()),this,SLOT(changeName())); 62 | connect(sexBtn,SIGNAL(clicked()),this,SLOT(changeSex())); 63 | connect(ageBtn,SIGNAL(clicked()),this,SLOT(changeAge())); 64 | connect(scoreBtn,SIGNAL(clicked()),this,SLOT(changeScore())); 65 | } 66 | 67 | void InputDlg::changeName() 68 | { 69 | bool isOk = false; 70 | QString text = QInputDialog::getText(this,tr("标准字符串输入对话框"), 71 | tr("请输入姓名:"),QLineEdit::Normal,nameLabel2->text(),&isOk); 72 | if(isOk && !text.isEmpty()){ 73 | nameLabel2->setText(text); 74 | } 75 | } 76 | 77 | void InputDlg::changeSex() 78 | { 79 | QStringList sexItems; 80 | sexItems.push_back(tr("男")); 81 | sexItems.push_back(tr("女")); 82 | bool isOk = false; 83 | QString sexItem = QInputDialog::getItem(this,tr("标准条目选择对话框"), 84 | tr("请选择性别:"),sexItems,0,false,&isOk); 85 | if(isOk && !sexItem.isEmpty()){ 86 | sexLabel2->setText(sexItem); 87 | } 88 | } 89 | 90 | void InputDlg::changeAge() 91 | { 92 | bool isOk = false; 93 | int age = QInputDialog::getInt(this,tr("标准int类型输入对话框"), 94 | tr("请输入年龄:"),ageLabel2->text().toInt(&isOk),0,100,1,&isOk); 95 | if(isOk){ 96 | ageLabel2->setText(QString(tr("%1")).arg(age)); 97 | } 98 | } 99 | 100 | void InputDlg::changeScore() 101 | { 102 | bool isOk = false; 103 | double score = QInputDialog::getDouble(this,tr("标准double类型输入对话框"), 104 | tr("请输入分数:"),scoreLabel2->text().toDouble(&isOk),0,100,1,&isOk); 105 | if(isOk){ 106 | scoreLabel2->setText(QString(tr("%1")).arg(score)); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/inputdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef INPUTDLG_H 2 | #define INPUTDLG_H 3 | 4 | #include 5 | #include // 用于布局设计 6 | #include 7 | #include 8 | 9 | class InputDlg : public QDialog 10 | { 11 | Q_OBJECT // 用于signal和slot机制的使用 12 | public: 13 | InputDlg(QWidget *parent = nullptr); 14 | private slots: 15 | void changeName(); // 演示字符串类型 nameBtn 16 | void changeSex(); // 演示下拉列表 17 | void changeAge(); // 演示int数据类型 18 | void changeScore(); // 演示double数据类型 19 | private: 20 | QGridLayout *mainLayout; 21 | // 用于 标准输入对话框 演示字符串类型 22 | QLabel *nameLabel1; // 显示 姓名 23 | QLabel *nameLabel2; // 显示 具体名字 由按钮弹框修改,标准输入对话框的字符串类型 24 | QPushButton *nameBtn; // 修改 姓名的按钮 25 | 26 | // 用于 标准输入对话框 演示下拉列表 27 | QLabel *sexLabel1; 28 | QLabel *sexLabel2; 29 | QPushButton *sexBtn; 30 | 31 | // 用于 标准输入对话框 演示int数据类型 32 | QLabel *ageLabel1; 33 | QLabel *ageLabel2; 34 | QPushButton *ageBtn; 35 | 36 | // 用于 标准输入对话框 演示double数据类型 37 | QLabel *scoreLabel1; 38 | QLabel *scoreLabel2; 39 | QPushButton *scoreBtn; 40 | }; 41 | 42 | #endif // INPUTDLG_H 43 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "dialog.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Dialog w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/msgboxdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "msgboxdlg.h" 2 | #include 3 | 4 | MsgBoxDlg::MsgBoxDlg(QWidget *parent) 5 | :QDialog(parent) 6 | { 7 | setWindowTitle(tr("标准消息对话框实例")); 8 | label = new QLabel; 9 | label->setText(tr("请选择一种消息框")); 10 | 11 | questionBtn = new QPushButton; 12 | questionBtn->setText(tr("QuestionMsg")); 13 | informationBtn = new QPushButton; 14 | informationBtn->setText(tr("InformationMsg")); 15 | warningBtn = new QPushButton; 16 | warningBtn->setText(tr("WarningMsg")); 17 | criticalBtn = new QPushButton; 18 | criticalBtn->setText(tr("CriticalMsg")); 19 | aboutBtn = new QPushButton; 20 | aboutBtn->setText(tr("AboutMsg")); 21 | aboutQtBtn = new QPushButton; 22 | aboutQtBtn->setText(tr("AboutQtMsg")); 23 | 24 | mainLayout = new QGridLayout(this); 25 | mainLayout->addWidget(label,0,0,1,2); 26 | mainLayout->addWidget(questionBtn,1,0); 27 | mainLayout->addWidget(informationBtn,1,1); 28 | mainLayout->addWidget(warningBtn,2,0); 29 | mainLayout->addWidget(criticalBtn,2,1); 30 | mainLayout->addWidget(aboutBtn,3,0); 31 | mainLayout->addWidget(aboutQtBtn,3,1); 32 | 33 | connect(questionBtn,SIGNAL(clicked()),this,SLOT(showQuestionMsg())); 34 | connect(informationBtn,SIGNAL(clicked()),this,SLOT(showInformationMsg())); 35 | connect(warningBtn,SIGNAL(clicked()),this,SLOT(showWarningMsg())); 36 | connect(criticalBtn,SIGNAL(clicked()),this,SLOT(showCriticalMsg())); 37 | connect(aboutBtn,SIGNAL(clicked()),this,SLOT(showAboutMsg())); 38 | connect(aboutQtBtn,SIGNAL(clicked()),this,SLOT(showAboutQtMsg())); 39 | } 40 | 41 | void MsgBoxDlg::showQuestionMsg() 42 | { 43 | label->setText(tr("Question Message Box")); 44 | 45 | auto ret = QMessageBox::question(this,tr("Question消息框"), 46 | tr("Question消息框显示演示"), 47 | QMessageBox::Ok|QMessageBox::Cancel,QMessageBox::Ok); 48 | 49 | switch(ret){ 50 | case QMessageBox::Ok: 51 | label->setText(tr("Question Button/OK")); 52 | break; 53 | case QMessageBox::Cancel: 54 | label->setText(tr("Question Button/Cancel")); 55 | break; 56 | default: 57 | break; 58 | } 59 | return; 60 | } 61 | 62 | void MsgBoxDlg::showInformationMsg() 63 | { 64 | label->setText(tr("Information Message Box")); 65 | QMessageBox::information(this,tr("Information消息框"), 66 | tr("Information消息框显示演示")); 67 | return; 68 | } 69 | 70 | void MsgBoxDlg::showWarningMsg() 71 | { 72 | label->setText(tr("Warning Message Box")); 73 | 74 | auto ret = QMessageBox::warning(this,tr("Warning消息框"), 75 | tr("Warning消息框显示演示"), 76 | QMessageBox::Save|QMessageBox::Discard|QMessageBox::Cancel, 77 | QMessageBox::Save); 78 | 79 | switch(ret){ 80 | case QMessageBox::Save: 81 | label->setText(tr("Warning Button/Save")); 82 | break; 83 | case QMessageBox::Discard: 84 | label->setText(tr("Warning Button/Discard")); 85 | break; 86 | case QMessageBox::Cancel: 87 | label->setText(tr("Warning Button/Cancel")); 88 | break; 89 | default: 90 | break; 91 | } 92 | return; 93 | } 94 | 95 | void MsgBoxDlg::showCriticalMsg() 96 | { 97 | label->setText(tr("Critical Message Box")); 98 | QMessageBox::critical(this,tr("Critical消息框"), 99 | tr("Information消息框显示演示")); 100 | return; 101 | } 102 | 103 | void MsgBoxDlg::showAboutMsg() 104 | { 105 | label->setText(tr("About Message Box")); 106 | QMessageBox::about(this,tr("About消息框"), 107 | tr("About消息框显示演示")); 108 | return; 109 | } 110 | 111 | void MsgBoxDlg::showAboutQtMsg() 112 | { 113 | label->setText(tr("AboutQt Message Box")); 114 | QMessageBox::aboutQt(this,tr("AboutQt消息框")); 115 | return; 116 | } 117 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH401/DialogExample/msgboxdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef MSGBOXDLG_H 2 | #define MSGBOXDLG_H 3 | 4 | #include 5 | #include // 用于布局设计 6 | #include 7 | #include 8 | 9 | class MsgBoxDlg : public QDialog 10 | { 11 | Q_OBJECT 12 | public: 13 | MsgBoxDlg(QWidget *parent = nullptr); 14 | private slots: 15 | void showQuestionMsg(); // questionBtn 16 | void showInformationMsg(); // informationBtn 17 | void showWarningMsg(); // warningBtn 18 | void showCriticalMsg(); // criticalBtn 19 | void showAboutMsg(); // aboutBtn 20 | void showAboutQtMsg(); // aboutQtBtn 21 | private: 22 | QGridLayout *mainLayout; 23 | QLabel *label; // 显示选择了什么消息框 24 | QPushButton *questionBtn; 25 | QPushButton *informationBtn; 26 | QPushButton *warningBtn; 27 | QPushButton *criticalBtn; 28 | QPushButton *aboutBtn; 29 | QPushButton *aboutQtBtn; 30 | }; 31 | 32 | #endif // MSGBOXDLG_H 33 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/QToolBoxExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | drawer.cpp 21 | 22 | HEADERS += \ 23 | drawer.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | 30 | RESOURCES += \ 31 | head.qrc 32 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/drawer.cpp: -------------------------------------------------------------------------------- 1 | #include "drawer.h" 2 | #include 3 | 4 | Drawer::Drawer(QWidget *parent, Qt::WindowFlags f) 5 | :QToolBox(parent,f) 6 | { 7 | setWindowTitle(tr("My QToolBoxExample")); 8 | CreateGroupBox1(); 9 | CreateGroupBox2(); 10 | CreateGroupBox3(); 11 | 12 | addItem(groupbox1,tr("我的好友")); // QToolBox 中添加每个抽屉 13 | addItem(groupbox2,tr("陌生人")); 14 | addItem(groupbox3,tr("黑名单")); 15 | resize(1000,1200); 16 | } 17 | 18 | Drawer::~Drawer() 19 | { 20 | } 21 | 22 | void Drawer::CreateGroupBox1() 23 | { 24 | toolBtn1_1 = new QToolButton; 25 | toolBtn1_1->setText("张三"); 26 | QPixmap icon1_1(":/icon/1.png"); 27 | toolBtn1_1->setIcon(icon1_1); 28 | toolBtn1_1->setIconSize(icon1_1.size()); 29 | toolBtn1_1->setAutoRaise(true); // 鼠标离开时自动恢复为弹起状态 30 | // Qt::ToolButtonIconOnly 只显示图标 31 | // Qt::ToolButtonTextOnly 只显示文字 32 | // Qt::ToolButtonTextBesideIcon 文字显示在图标旁边 33 | // Qt::ToolButtonTextUnderIcon 文字显示在图标下 34 | // Qt::ToolButtonFollowStyle 遵循Style标准, 详见Qt帮助 35 | toolBtn1_1->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 36 | 37 | toolBtn1_2 = new QToolButton; 38 | toolBtn1_2->setText("李四"); 39 | QPixmap icon1_2(":/icon/2.png"); 40 | toolBtn1_2->setIcon(icon1_2); 41 | toolBtn1_2->setIconSize(icon1_2.size()); 42 | toolBtn1_2->setAutoRaise(true); 43 | toolBtn1_2->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 44 | 45 | 46 | toolBtn1_3 = new QToolButton; 47 | toolBtn1_3->setText("王五"); 48 | QPixmap icon1_3(":/icon/3.png"); 49 | toolBtn1_3->setIcon(icon1_3); 50 | toolBtn1_3->setIconSize(icon1_3.size()); 51 | toolBtn1_3->setAutoRaise(true); 52 | toolBtn1_3->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 53 | 54 | 55 | toolBtn1_4 = new QToolButton; 56 | toolBtn1_4->setText("赵六"); 57 | QPixmap icon1_4(":/icon/4.png"); 58 | toolBtn1_4->setIcon(icon1_4); 59 | toolBtn1_4->setIconSize(icon1_4.size()); 60 | toolBtn1_4->setAutoRaise(true); 61 | toolBtn1_4->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 62 | 63 | groupbox1 = new QGroupBox; // 对应每个抽屉 64 | layout1 = new QVBoxLayout(groupbox1); // QGroupBox 的布局 65 | layout1->setMargin(10); 66 | layout1->setAlignment(Qt::AlignHCenter);//对齐方式 67 | layout1->addWidget(toolBtn1_1); 68 | layout1->addWidget(toolBtn1_2); 69 | layout1->addWidget(toolBtn1_3); 70 | layout1->addWidget(toolBtn1_4); 71 | } 72 | 73 | void Drawer::CreateGroupBox2() 74 | { 75 | toolBtn2_1 = new QToolButton; 76 | toolBtn2_1->setText("小赵"); 77 | QPixmap icon2_1(":/icon/5.png"); 78 | toolBtn2_1->setIcon(icon2_1); 79 | toolBtn2_1->setIconSize(icon2_1.size()); 80 | toolBtn2_1->setAutoRaise(true); // 鼠标离开时自动恢复为弹起状态 81 | toolBtn2_1->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 82 | 83 | toolBtn2_2 = new QToolButton; 84 | toolBtn2_2->setText("小钱"); 85 | QPixmap icon2_2(":/icon/6.png"); 86 | toolBtn2_2->setIcon(icon2_2); 87 | toolBtn2_2->setIconSize(icon2_2.size()); 88 | toolBtn2_2->setAutoRaise(true); 89 | toolBtn2_2->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 90 | 91 | toolBtn2_3 = new QToolButton; 92 | toolBtn2_3->setText("小孙"); 93 | QPixmap icon2_3(":/icon/7.png"); 94 | toolBtn2_3->setIcon(icon2_3); 95 | toolBtn2_3->setIconSize(icon2_3.size()); 96 | toolBtn2_3->setAutoRaise(true); 97 | toolBtn2_3->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 98 | 99 | groupbox2 = new QGroupBox; // 对应每个抽屉 100 | layout2 = new QVBoxLayout(groupbox2); // QGroupBox 的布局 101 | layout2->setMargin(10); 102 | layout2->setAlignment(Qt::AlignLeft);//对齐方式 103 | layout2->addWidget(toolBtn2_1); 104 | layout2->addWidget(toolBtn2_2); 105 | layout2->addWidget(toolBtn2_3); 106 | } 107 | 108 | void Drawer::CreateGroupBox3() 109 | { 110 | toolBtn3_1 = new QToolButton; 111 | toolBtn3_1->setText("小明"); 112 | QPixmap icon3_1(":/icon/8.png"); 113 | toolBtn3_1->setIcon(icon3_1); 114 | toolBtn3_1->setIconSize(icon3_1.size()); 115 | toolBtn3_1->setAutoRaise(true); // 鼠标离开时自动恢复为弹起状态 116 | toolBtn3_1->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 117 | 118 | toolBtn3_2 = new QToolButton; 119 | toolBtn3_2->setText("大明"); 120 | QPixmap icon3_2(":/icon/9.png"); 121 | toolBtn3_2->setIcon(icon3_2); 122 | toolBtn3_2->setIconSize(icon3_2.size()); 123 | toolBtn3_2->setAutoRaise(true); 124 | toolBtn3_2->setToolButtonStyle(Qt::ToolButtonStyle::ToolButtonTextBesideIcon); 125 | 126 | groupbox3 = new QGroupBox; // 对应每个抽屉 127 | layout3 = new QVBoxLayout(groupbox3); // QGroupBox 的布局 128 | layout3->setMargin(10); 129 | layout3->setAlignment(Qt::AlignRight);//对齐方式 130 | layout3->addWidget(toolBtn3_1); 131 | layout3->addWidget(toolBtn3_2); 132 | } 133 | 134 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/drawer.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAWER_H 2 | #define DRAWER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | class Drawer : public QToolBox 10 | { 11 | Q_OBJECT 12 | 13 | public: 14 | Drawer(QWidget *parent = nullptr, Qt::WindowFlags f = Qt::WindowFlags()); 15 | ~Drawer(); 16 | private: 17 | QGroupBox *groupbox1; 18 | QVBoxLayout *layout1; 19 | QToolButton *toolBtn1_1; 20 | QToolButton *toolBtn1_2; 21 | QToolButton *toolBtn1_3; 22 | QToolButton *toolBtn1_4; 23 | 24 | QGroupBox *groupbox2; 25 | QVBoxLayout *layout2; 26 | QToolButton *toolBtn2_1; 27 | QToolButton *toolBtn2_2; 28 | QToolButton *toolBtn2_3; 29 | 30 | QGroupBox *groupbox3; 31 | QVBoxLayout *layout3; 32 | QToolButton *toolBtn3_1; 33 | QToolButton *toolBtn3_2; 34 | 35 | void CreateGroupBox1(); 36 | void CreateGroupBox2(); 37 | void CreateGroupBox3(); 38 | }; 39 | #endif // DRAWER_H 40 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/head.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon/1.png 4 | icon/2.png 5 | icon/3.png 6 | icon/4.png 7 | icon/5.png 8 | icon/6.png 9 | icon/7.png 10 | icon/8.png 11 | icon/9.png 12 | 13 | 14 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/1.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/2.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/3.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/4.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/5.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/6.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/7.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/8.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/icon/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH402/QToolBoxExample/icon/9.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH402/QToolBoxExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "drawer.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Drawer w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH403/ProgressExample/ProgressExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | progressdlg.cpp 21 | 22 | HEADERS += \ 23 | progressdlg.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH403/ProgressExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "progressdlg.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | ProgressDlg w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH403/ProgressExample/progressdlg.cpp: -------------------------------------------------------------------------------- 1 | #include "progressdlg.h" 2 | #include 3 | 4 | ProgressDlg::ProgressDlg(QWidget *parent) 5 | : QDialog(parent) 6 | { 7 | setWindowTitle(tr("ProgressExample")); 8 | fileNumLabel = new QLabel(); 9 | fileNumLabel->setText(tr("文件数目:")); 10 | fileNumLineEdit = new QLineEdit; 11 | fileNumLineEdit->setText(tr("1000000")); 12 | progressType = new QLabel; 13 | progressType->setText(tr("显示类型")); 14 | typeComboBox = new QComboBox; 15 | typeComboBox->addItem(tr("QProgressBar")); 16 | typeComboBox->addItem(tr("QProgressDialog")); 17 | progressBar = new QProgressBar; 18 | startBtn = new QPushButton; 19 | startBtn->setText(tr("开始")); 20 | 21 | mainLayout = new QGridLayout(this); 22 | mainLayout->addWidget(fileNumLabel,0,0); 23 | mainLayout->addWidget(fileNumLineEdit,0,1); 24 | mainLayout->addWidget(progressType,1,0); 25 | mainLayout->addWidget(typeComboBox,1,1); 26 | mainLayout->addWidget(progressBar,2,0,1,2); 27 | mainLayout->addWidget(startBtn,3,1); 28 | mainLayout->setMargin(15); 29 | mainLayout->setSpacing(10); 30 | 31 | connect(startBtn,SIGNAL(clicked()),this,SLOT(startProgress())); 32 | } 33 | 34 | ProgressDlg::~ProgressDlg() 35 | { 36 | } 37 | 38 | void ProgressDlg::startProgress() 39 | { 40 | bool ok = false; 41 | int num = fileNumLineEdit->text().toInt(&ok); 42 | if(ok){ 43 | int index = typeComboBox->currentIndex(); 44 | if(index == 0){// 选择了 QProgressBar 45 | startBtn->setDisabled(true); 46 | // QProgressBar 有几个重要属性 47 | // 1、minimum\maximum: 决定进度条指示的最小值和最大值 48 | // 2、format: 决定进度条显示文字的格式。`%p%` 显示完成百分比,默认方式; `%v`显示当前进度值; `%m`显示总的步进值 49 | // 3、invertedAppearance : 反向显示 50 | progressBar->setRange(0,num); 51 | progressBar->setFormat("%p%"); // %p%[0%-100%] %v[0-num] %m 52 | progressBar->setInvertedAppearance(false); 53 | for (int i = 1; isetValue(i); 55 | } 56 | startBtn->setDisabled(false); 57 | } else if(index == 1){ 58 | // QProgressDialog几个重要属性 59 | // 1、minimum\maximum: 决定进度条指示的最小值和最大值 60 | // 2、minimumDuration: 进度条显示等待时间,系统会根据工作量预估,若大于则显示,若小于不显示 61 | QProgressDialog *progressDlg = new QProgressDialog; 62 | progressDlg->setWindowModality(Qt::WindowModal); // 设置模态显示 63 | progressDlg->setMinimumDuration(1); // 默认4秒 64 | progressDlg->setRange(0,num); 65 | progressDlg->setWindowTitle(tr("Please Waiting...")); 66 | progressDlg->setLabelText(tr("Coping....")); 67 | progressDlg->setCancelButtonText(tr("Cancel")); 68 | for (int i = 1; isetValue(i); 70 | if(progressDlg->wasCanceled()){ 71 | return; 72 | } 73 | } 74 | } 75 | } 76 | } 77 | 78 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH403/ProgressExample/progressdlg.h: -------------------------------------------------------------------------------- 1 | #ifndef PROGRESSDLG_H 2 | #define PROGRESSDLG_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class ProgressDlg : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | ProgressDlg(QWidget *parent = nullptr); 19 | ~ProgressDlg(); 20 | private slots: 21 | void startProgress(); 22 | private: 23 | QLabel *fileNumLabel; 24 | QLineEdit *fileNumLineEdit; 25 | QLabel *progressType; 26 | QComboBox *typeComboBox; 27 | QProgressBar *progressBar; 28 | QPushButton *startBtn; 29 | QGridLayout *mainLayout; 30 | }; 31 | #endif // PROGRESSDLG_H 32 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH404/PaletteExample/PaletteExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | palette.cpp 21 | 22 | HEADERS += \ 23 | palette.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH404/PaletteExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "palette.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Palette w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH404/PaletteExample/palette.h: -------------------------------------------------------------------------------- 1 | #ifndef PALETTE_H 2 | #define PALETTE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | 13 | class Palette : public QDialog 14 | { 15 | Q_OBJECT 16 | 17 | public: 18 | Palette(QWidget *parent = nullptr); 19 | ~Palette(); 20 | private slots: 21 | void ShowWindow(); // 背景色 22 | void ShowWindowText(); // 前景色 23 | void ShowButton(); // 按钮背景色 24 | void ShowButtonText(); //按钮前景色 25 | void ShowBase(); 26 | private: 27 | void CreateCtrlFrame(); // 完成颜色选取区域的创建 28 | void CreateDisplayFrame(); // 完成展示区域的创建 29 | void fillColorList(QComboBox *comboBox); // 颜色选取区域 颜色下拉列表中插入颜色 30 | private: 31 | QHBoxLayout *mainLayout; 32 | // 颜色选择部分 33 | QFrame *ctrlFrame; 34 | QLabel *windowLabel; // 背景色 35 | QComboBox *windowComboBox; 36 | QLabel *windowTextLabel; // 前景色 37 | QComboBox *windowTextComboBox; 38 | QLabel *buttonLabel; // 按钮背景色 39 | QComboBox *buttonComboBox; 40 | QLabel *buttonTextLabel; // 按钮前景色 41 | QComboBox *buttonTextComboBox; 42 | QLabel *baseLabel; // 主要用作文本输入小部件的背景颜色 43 | QComboBox *baseComboBox; 44 | 45 | //展示部分 46 | QFrame *displayFrame; 47 | QLabel *displayLabel1; 48 | QComboBox *displayComboBox; 49 | QLabel *displayLabel2; 50 | QLineEdit *displayLineEdit; 51 | QTextEdit *displayTextEdit; 52 | QPushButton *displayOkBtn; 53 | QPushButton *displayCancelBtn; 54 | }; 55 | #endif // PALETTE_H 56 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH405/ClockExample/ClockExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | digiclock.cpp 21 | 22 | HEADERS += \ 23 | digiclock.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH405/ClockExample/digiclock.cpp: -------------------------------------------------------------------------------- 1 | #include "digiclock.h" 2 | #include 3 | #include 4 | #include 5 | 6 | DigiClock::DigiClock(QWidget *parent) 7 | : QLCDNumber(parent) 8 | { 9 | colorIndex = 0; 10 | colorList = {Qt::darkRed,Qt::darkGreen,Qt::darkBlue, 11 | Qt:: darkCyan,Qt::darkMagenta,Qt::darkYellow,Qt::darkGray}; 12 | //设值参数 13 | this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗体标识,无边框无标题栏 14 | this->setDecMode(); // 十进制 15 | this->setDigitCount(19); //显示个数 16 | this->setWindowOpacity(0.5); // 设置透明度 0 全透明 1 全不透明 17 | this->setSegmentStyle(QLCDNumber::Flat); // flat 才能改变 前景色 18 | this->resize(600,100); // 重设大小 19 | 20 | QPalette p = this->palette(); 21 | p.setColor(QPalette::Window,Qt::lightGray); // 背景色 22 | p.setColor(QPalette::WindowText,colorList.at(colorIndex)); // 前景色 字体颜色 23 | this->setPalette(p); 24 | 25 | QTimer *timer = new QTimer(this); //定时器用于 每秒刷新显示 26 | connect(timer,SIGNAL(timeout()),this,SLOT(showTime())); 27 | timer->start(1000); 28 | this->showTime(); // 初始时间显示 29 | showColonFlag = true; 30 | } 31 | 32 | DigiClock::~DigiClock() 33 | { 34 | } 35 | 36 | void DigiClock::mousePressEvent(QMouseEvent *event) 37 | { 38 | if(event->button() == Qt::LeftButton){ // 注意 mouseMoveEvent 的区别 39 | dragOffsetPoint = event->globalPos() - this->frameGeometry().topLeft(); 40 | event->accept(); 41 | } 42 | if(event->button() == Qt::RightButton){ 43 | close(); // 关闭 44 | } 45 | } 46 | 47 | void DigiClock::mouseMoveEvent(QMouseEvent *event) 48 | { 49 | // 注意这里和 mousePressEvent 的区别,在mouseMoveEvent中 event->button() 始终为 NoButton 50 | if(event->buttons() & Qt::LeftButton){ 51 | move(event->globalPos() - dragOffsetPoint); 52 | event->accept(); 53 | } 54 | } 55 | 56 | void DigiClock::mouseDoubleClickEvent(QMouseEvent *event) 57 | { 58 | if(event->button() == Qt::LeftButton){ 59 | colorIndex++; 60 | if(colorIndex >= colorList.size()){ 61 | colorIndex = 0; 62 | } 63 | QPalette p = this->palette(); 64 | p.setColor(QPalette::WindowText,colorList.at(colorIndex)); // 前景色 字体颜色 65 | this->setPalette(p); 66 | event->accept(); 67 | } 68 | } 69 | 70 | void DigiClock::showTime() 71 | { 72 | QDateTime dateTime = QDateTime::currentDateTime(); 73 | QString text = dateTime.toString("yyyy-MM-dd hh:mm:ss"); // 19个数 74 | if(showColonFlag){ 75 | showColonFlag = false; 76 | text[16] = ':'; 77 | } else { 78 | showColonFlag = true; 79 | text[16] = ' '; 80 | } 81 | this->display(text); // 显示 82 | } 83 | 84 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH405/ClockExample/digiclock.h: -------------------------------------------------------------------------------- 1 | #ifndef DIGICLOCK_H 2 | #define DIGICLOCK_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class DigiClock : public QLCDNumber 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | DigiClock(QWidget *parent = nullptr); 14 | ~DigiClock(); 15 | void mousePressEvent(QMouseEvent *event); // 鼠标按下事件响应函数 16 | void mouseMoveEvent(QMouseEvent *event); // 鼠标移动事件响应函数 17 | void mouseDoubleClickEvent(QMouseEvent *event); // 鼠标双击事件响应函数 18 | public slots: 19 | void showTime(); 20 | private: 21 | int colorIndex; // 颜色序号 22 | QList colorList; // 颜色列表 23 | bool showColonFlag; // 是否显示 :, 模拟闪烁 24 | QPoint dragOffsetPoint; // 保存拖拽鼠标点 相对时钟窗体左上角位置 的偏移值 25 | 26 | }; 27 | #endif // DIGICLOCK_H 28 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH405/ClockExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "digiclock.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | DigiClock w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH406/ExtensibleDialogExample/ExtensibleDialogExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | extensibledlg.cpp 21 | 22 | HEADERS += \ 23 | extensibledlg.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH406/ExtensibleDialogExample/extensibledlg.cpp: -------------------------------------------------------------------------------- 1 | #include "extensibledlg.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | ExtensibleDlg::ExtensibleDlg(QWidget *parent) 9 | : QDialog(parent) 10 | { 11 | setWindowTitle(tr("Extension Dialog Example")); 12 | CreateBaseInfoPart(); 13 | CreateDetailInfoPart(); 14 | mainLayout = new QVBoxLayout(this); 15 | mainLayout->addWidget(baseInfoPart); 16 | mainLayout->addWidget(detailInfoPart); 17 | mainLayout->setSizeConstraint(QLayout::SetFixedSize); // 设置窗体大小固定,不能通过拖拽改变大小 18 | } 19 | 20 | ExtensibleDlg::~ExtensibleDlg() 21 | { 22 | } 23 | 24 | void ExtensibleDlg::showDetailInfoPart() 25 | { 26 | if(detailInfoPart->isHidden()){ 27 | detailInfoPart->show(); 28 | } else { 29 | detailInfoPart->hide(); 30 | } 31 | } 32 | 33 | void ExtensibleDlg::CreateBaseInfoPart() 34 | { 35 | baseInfoPart = new QWidget; 36 | // 控件 37 | QLabel *nameLabel = new QLabel(tr("姓名:")); 38 | QLineEdit *nameLineEdit = new QLineEdit; 39 | QLabel *sexLabel = new QLabel(tr("性别:")); 40 | QComboBox *sexComboBox = new QComboBox; 41 | sexComboBox->addItem(tr("男")); 42 | sexComboBox->addItem(tr("女")); 43 | QPushButton *okBtn = new QPushButton(tr("确定")); 44 | QPushButton *detailBtn = new QPushButton(tr("详细")); 45 | // 信号槽 46 | connect(detailBtn,SIGNAL(clicked()),this,SLOT(showDetailInfoPart())); 47 | // 布局 48 | QGridLayout *baseInfoLayout = new QGridLayout(baseInfoPart); 49 | baseInfoLayout->addWidget(nameLabel,0,0); 50 | baseInfoLayout->addWidget(nameLineEdit,0,1); 51 | baseInfoLayout->addWidget(okBtn,0,2); 52 | baseInfoLayout->addWidget(sexLabel,1,0); 53 | baseInfoLayout->addWidget(sexComboBox,1,1); 54 | baseInfoLayout->addWidget(detailBtn,1,2); 55 | baseInfoLayout->setSpacing(10); 56 | } 57 | 58 | void ExtensibleDlg::CreateDetailInfoPart() 59 | { 60 | detailInfoPart = new QWidget; 61 | QLabel *ageLabel = new QLabel(tr("年龄:")); 62 | QLineEdit *ageLineEdit = new QLineEdit; 63 | QLabel *departmentLabel = new QLabel(tr("部门:")); 64 | QComboBox *departmentComboBox = new QComboBox; 65 | departmentComboBox->addItem(tr("部门1")); 66 | departmentComboBox->addItem(tr("部门2")); 67 | QLabel *emailLabel = new QLabel(tr("Email:")); 68 | QLineEdit *emailLineEdit = new QLineEdit; 69 | // 布局 70 | QGridLayout *detailInfoLayout = new QGridLayout(detailInfoPart); 71 | detailInfoLayout->addWidget(ageLabel,0,0); 72 | detailInfoLayout->addWidget(ageLineEdit,0,1); 73 | detailInfoLayout->addWidget(departmentLabel,1,0); 74 | detailInfoLayout->addWidget(departmentComboBox,1,1); 75 | detailInfoLayout->addWidget(emailLabel,2,0); 76 | detailInfoLayout->addWidget(emailLineEdit,2,1); 77 | detailInfoPart->hide(); // 一开始隐藏 78 | } 79 | 80 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH406/ExtensibleDialogExample/extensibledlg.h: -------------------------------------------------------------------------------- 1 | #ifndef EXTENSIBLEDLG_H 2 | #define EXTENSIBLEDLG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class ExtensibleDlg : public QDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | ExtensibleDlg(QWidget *parent = nullptr); 14 | ~ExtensibleDlg(); 15 | private slots: 16 | void showDetailInfoPart(); // 按钮响应用于 显示隐藏 扩展部分 17 | private: 18 | void CreateBaseInfoPart(); // 创建基础信息部分 19 | void CreateDetailInfoPart(); // 创建扩展的细节信息部分 20 | QWidget *baseInfoPart; // 础信息部分 21 | QWidget *detailInfoPart; // 细节信息部分 22 | QVBoxLayout *mainLayout; // 布局 23 | }; 24 | #endif // EXTENSIBLEDLG_H 25 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH406/ExtensibleDialogExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "extensibledlg.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | ExtensibleDlg w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH407/IrregularShapeExample/IrregularShapeExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | shapewidget.cpp 21 | 22 | HEADERS += \ 23 | shapewidget.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | 30 | RESOURCES += \ 31 | sources.qrc 32 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH407/IrregularShapeExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "shapewidget.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | ShapeWidget w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH407/IrregularShapeExample/shape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH4/CH407/IrregularShapeExample/shape.png -------------------------------------------------------------------------------- /CodeDemo/CH4/CH407/IrregularShapeExample/shapewidget.cpp: -------------------------------------------------------------------------------- 1 | #include "shapewidget.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | ShapeWidget::ShapeWidget(QWidget *parent) 8 | : QWidget(parent) 9 | { 10 | QPixmap pix; 11 | pix.load(":/shape.png"); 12 | resize(pix.size()); 13 | setMask(QBitmap(pix.mask()));// 设置遮罩 mask() 获取pix图片自身的遮罩 14 | // 此时窗体变为 shape.png 的形状,但是是空白的 15 | } 16 | 17 | ShapeWidget::~ShapeWidget() 18 | { 19 | } 20 | 21 | void ShapeWidget::mouseMoveEvent(QMouseEvent *event) 22 | { 23 | if(event->buttons() & Qt::LeftButton){ 24 | move(event->globalPos() - dragPosition); 25 | event->accept(); 26 | } 27 | } 28 | 29 | void ShapeWidget::mousePressEvent(QMouseEvent *event) 30 | { 31 | if(event->button() == Qt::LeftButton){ 32 | dragPosition = event->globalPos() - frameGeometry().topLeft(); 33 | event->accept(); 34 | } 35 | if(event->button() == Qt::RightButton){ 36 | close(); 37 | } 38 | } 39 | 40 | void ShapeWidget::paintEvent(QPaintEvent *event) 41 | { 42 | // 在窗体上绘制图片 43 | QPainter painter(this); 44 | painter.drawPixmap(0,0,QPixmap(":/shape.png")); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH407/IrregularShapeExample/shapewidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SHAPEWIDGET_H 2 | #define SHAPEWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | class ShapeWidget : public QWidget 8 | { 9 | Q_OBJECT 10 | 11 | public: 12 | ShapeWidget(QWidget *parent = nullptr); 13 | ~ShapeWidget(); 14 | protected: 15 | void mouseMoveEvent(QMouseEvent *event) override; 16 | void mousePressEvent(QMouseEvent *event) override; 17 | void paintEvent(QPaintEvent *event) override; 18 | private: 19 | QPoint dragPosition; // 记录拖拽时 鼠标点击位置 与 窗体左上角的 偏移 20 | }; 21 | #endif // SHAPEWIDGET_H 22 | -------------------------------------------------------------------------------- /CodeDemo/CH4/CH407/IrregularShapeExample/sources.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | shape.png 4 | 5 | 6 | -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/Resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | icon/bold.png 4 | icon/center.png 5 | icon/color.png 6 | icon/copy.png 7 | icon/cut.png 8 | icon/italic.png 9 | icon/justify.png 10 | icon/new.png 11 | icon/open.png 12 | icon/paste.png 13 | icon/printText.png 14 | icon/redo.png 15 | icon/right.png 16 | icon/underline.png 17 | icon/undo.png 18 | icon/left.png 19 | 20 | 21 | -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/SimpleTextEditor.pro: -------------------------------------------------------------------------------- 1 | QT += core gui printsupport 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | showwidget.cpp \ 21 | simpletexteditor.cpp 22 | 23 | HEADERS += \ 24 | showwidget.h \ 25 | simpletexteditor.h 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | 32 | RESOURCES += \ 33 | Resource.qrc 34 | -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/bold.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/bold.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/center.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/center.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/color.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/color.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/copy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/copy.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/cut.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/cut.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/italic.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/italic.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/justify.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/justify.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/left.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/left.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/new.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/new.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/open.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/open.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/paste.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/paste.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/printText.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/printText.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/redo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/redo.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/right.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/right.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/underline.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/underline.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/icon/undo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH5/CH501/SimpleTextEditor/icon/undo.png -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/main.cpp: -------------------------------------------------------------------------------- 1 | #include "simpletexteditor.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | QFont f("楷体",12); //设置显示的字体格式 9 | a.setFont(f); 10 | SimpleTextEditor w; 11 | w.show(); 12 | return a.exec(); 13 | } 14 | -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/showwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "showwidget.h" 2 | #include 3 | 4 | ShowWidget::ShowWidget(QWidget *parent) : QWidget(parent) 5 | { 6 | text = new QTextEdit(this); 7 | QGridLayout *showWidgetLayout = new QGridLayout(this); 8 | showWidgetLayout->addWidget(text); 9 | } 10 | -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/showwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef SHOWWIDGET_H 2 | #define SHOWWIDGET_H 3 | 4 | #include 5 | #include 6 | 7 | class ShowWidget : public QWidget 8 | { 9 | Q_OBJECT 10 | public: 11 | explicit ShowWidget(QWidget *parent = nullptr); 12 | QTextEdit *text; 13 | signals: 14 | 15 | }; 16 | 17 | #endif // SHOWWIDGET_H 18 | -------------------------------------------------------------------------------- /CodeDemo/CH5/CH501/SimpleTextEditor/simpletexteditor.h: -------------------------------------------------------------------------------- 1 | #ifndef SIMPLETEXTEDITOR_H 2 | #define SIMPLETEXTEDITOR_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include "showwidget.h" 14 | 15 | class SimpleTextEditor : public QMainWindow 16 | { 17 | Q_OBJECT 18 | 19 | public: 20 | SimpleTextEditor(QWidget *parent = nullptr); 21 | ~SimpleTextEditor(); 22 | 23 | void CreateActions(); // 创建动作 24 | void CreateMenus(); // 创建菜单 25 | void CreateToolBars(); // 创建工具栏 26 | protected slots: 27 | void NewFile(); // 新建文件 28 | void OpenFile(); // 打开文件 29 | void PrintFile(); // 打印文件 30 | 31 | // 字体设置项 32 | void SetFontComboBox(QString comboStr); // 设置 字体 33 | void SetSizeSpinBox(QString spinValue); // 设置 字号 34 | void SetBoldBtn(); // 设置 加粗 35 | void SetItalicBtn(); // 设置 斜体 36 | void SetUnderlineBtn(); // 设置 下划线 37 | void SetColorBtn(); // 设置 颜色 38 | void ShowCurrentFormatChanged(const QTextCharFormat &fmt); // 根据光标处字体格式 变化刷新 工具上的显示 39 | // 排版设置项 40 | void SetAlignment (QAction *act); // 设置 段落对齐方式 41 | void SetList(int index); // 设置排序 42 | void ShowCursorPositionChanged(); // 光标位置发生变化 刷新 排版工具栏的显示 43 | private: 44 | void LoadFile(QString fileName); // 加载文件 45 | void CreateFontToolBar(); // 创建 文本编辑 字体项 工具栏 46 | void SetTextCharFormat(QTextCharFormat format); // 设置format 47 | void CreateTypesettingToolbar(); // 创建 排版 工具栏 对齐方式和排序方式 48 | private: 49 | QString fileName; // 打开的文件名 50 | ShowWidget *showWidget; //中心部件 51 | 52 | QMenu *fileMenu; // 文件 菜单 53 | QMenu *editMenu; // 编辑 菜单 54 | 55 | // 文件菜单项 56 | QAction *openFileAction; // 打开 57 | QAction *newFileAction; // 新建 58 | QAction *printFileAction; // 打印 59 | QAction *exitAction; // 退出 60 | 61 | // 编辑菜单项 62 | QAction *copyAction; // 复制 63 | QAction *cutAction; // 剪切 64 | QAction *pasteAction; // 粘贴 65 | QAction *undoAction; // 撤销 66 | QAction *redoAction; // 重做 67 | QAction *aboutAction; // 关于 68 | 69 | // 工具栏 70 | QToolBar *fileToolBar; // 文件 71 | QToolBar *editToolBar; // 编辑 72 | QToolBar *doToolBar; // undo redo 73 | 74 | // 字体设置项 75 | QLabel *fontLabel1; 76 | QFontComboBox *fontComboBox; 77 | // 字号 78 | QLabel *fontLabel2; 79 | QComboBox *sizeComboBox; 80 | // 加粗 按钮 81 | QToolButton *boldBtn; 82 | // 斜体 按钮 83 | QToolButton *italicBtn; 84 | // 下划线 按钮 85 | QToolButton *underlineBtn; 86 | // 颜色 按钮 87 | QToolButton *colorBtn; 88 | // 字体工具栏 89 | QToolBar *fontToolBar; 90 | 91 | // 排版设置项 92 | // 文本排序 方式 93 | QLabel *listLabel; 94 | QComboBox *listComboBox; 95 | // 文本段落对其方式 96 | QActionGroup *actGrp; 97 | QAction *leftAction; // 左对齐 98 | QAction *rightAction; // 右对齐 99 | QAction *centerAction; // 居中对齐 100 | QAction *justifyAction; // 两端对齐 101 | // 排版工具栏 102 | QToolBar *listToolBar; 103 | }; 104 | #endif // SIMPLETEXTEDITOR_H 105 | -------------------------------------------------------------------------------- /CodeDemo/CH5/QMainWindowTest/QMainWindowTest/QMainWindowTest.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | mainwindow.cpp 21 | 22 | HEADERS += \ 23 | mainwindow.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /CodeDemo/CH5/QMainWindowTest/QMainWindowTest/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | MainWindow w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH5/QMainWindowTest/QMainWindowTest/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | MainWindow::MainWindow(QWidget *parent) 13 | : QMainWindow(parent) 14 | { 15 | QMenuBar* menubar = menuBar(); 16 | QMenu* menu = new QMenu(tr("新建")); 17 | QAction* action = new QAction(tr("New")); // 18 | 19 | menu->addAction(action); 20 | menubar->addMenu(menu); 21 | action->setShortcut(tr("Ctrl+N")); 22 | action->setStatusTip(tr("新建一个文件")); 23 | 24 | QStatusBar *statusbar = statusBar(); 25 | QLabel *label = new QLabel("Status Bar Label"); 26 | QLineEdit *lineEdit = new QLineEdit("Status Bar LineEdit"); 27 | 28 | //statusbar->showMessage("欢迎",3000); // 指定的字符串作为提示信息显示在状态栏左侧,并且第二个是指定显示的时间 29 | statusbar->addWidget(label); 30 | statusbar->addPermanentWidget(lineEdit); 31 | 32 | QToolBar *toolBar = addToolBar(tr("File")); 33 | toolBar->addAction(action); 34 | // 设置停靠区域 默认为 AllToolBarAreas 35 | // TopToolBarArea BottomToolBarArea LeftToolBarArea RightToolBarArea AllToolBarAreas 36 | toolBar->setAllowedAreas(Qt::TopToolBarArea|Qt::LeftToolBarArea); 37 | //toolBar->setMovable(false); // 设置可移动性 38 | 39 | // 停靠窗口1 40 | // 步骤1 创建一个`QDockWidget`对象的停靠窗体 41 | QDockWidget *dock1 = new QDockWidget(tr("停靠窗口1"),this); 42 | // 步骤2 设置此停靠窗体的属性,通常调用 `setFeatures()`以及 `setAllowedAreas()` 43 | dock1->setFeatures(QDockWidget::DockWidgetMovable); // 可移动 44 | dock1->setAllowedAreas(Qt::LeftDockWidgetArea|Qt::RightDockWidgetArea); // 可 左侧停靠 和 右侧停靠 45 | //dock1->setFloating(true); // 不设置 不能悬浮 46 | // 步骤3 新建一个要插入停靠窗体的控件,比如 `QListWidget`、`QTextEdit` 47 | QLineEdit *textEdit1 = new QLineEdit(this); 48 | textEdit1->setText(tr("停靠窗口1,可移动到左侧停靠和右侧停靠")); 49 | // 步骤4 将控件插入停靠窗体,调用`QDockWidget`的`setWidget()`方法 50 | dock1->setWidget(textEdit1); 51 | // 步骤5 使用 `addDockWidget()`方法在`MainWindow`中加入此停靠窗体 52 | addDockWidget(Qt::LeftDockWidgetArea,dock1); 53 | 54 | QDockWidget *dockWidget = new QDockWidget(tr("DockWidget")); 55 | QListWidget *listWidget = new QListWidget; 56 | listWidget->addItem(tr("Item1")); 57 | listWidget->addItem(tr("Item2")); 58 | listWidget->addItem(tr("Item3")); 59 | dockWidget->setWidget(listWidget); 60 | dockWidget->setFloating(false); // 浮动主窗口内,可手动脱离 61 | //LeftDockWidgetArea RightDockWidgetArea TopDockWidgetArea BottomDockWidgetArea AllDockWidgetAreas 62 | dockWidget->setAllowedAreas(Qt::BottomDockWidgetArea|Qt::TopDockWidgetArea); 63 | addDockWidget(Qt::TopDockWidgetArea,dockWidget); 64 | 65 | QTextEdit *textEdit = new QTextEdit(this); 66 | textEdit->setText(tr("主窗口")); 67 | textEdit->setAlignment(Qt::AlignCenter); 68 | this->setCentralWidget(textEdit); // 设置 textEdit 为主窗口的中央窗体 69 | } 70 | 71 | MainWindow::~MainWindow() 72 | { 73 | } 74 | 75 | -------------------------------------------------------------------------------- /CodeDemo/CH5/QMainWindowTest/QMainWindowTest/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | 6 | class MainWindow : public QMainWindow 7 | { 8 | Q_OBJECT 9 | 10 | public: 11 | MainWindow(QWidget *parent = nullptr); 12 | ~MainWindow(); 13 | }; 14 | #endif // MAINWINDOW_H 15 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH601/CoordinateExample/CoordinateExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | main.cpp \ 20 | coordinate.cpp 21 | 22 | HEADERS += \ 23 | coordinate.h 24 | 25 | # Default rules for deployment. 26 | qnx: target.path = /tmp/$${TARGET}/bin 27 | else: unix:!android: target.path = /opt/$${TARGET}/bin 28 | !isEmpty(target.path): INSTALLS += target 29 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH601/CoordinateExample/coordinate.cpp: -------------------------------------------------------------------------------- 1 | #include "coordinate.h" 2 | 3 | Coordinate::Coordinate(QWidget *parent) 4 | : QDialog(parent) 5 | { 6 | setWindowTitle(tr("坐标相关函数")); 7 | // x() 8 | xLabel = new QLabel(tr("x():")); 9 | xValueLabel = new QLabel(); 10 | // y() 11 | yLabel = new QLabel(tr("y():")); 12 | yValueLabel = new QLabel(); 13 | // pos() 14 | posLabel = new QLabel(tr("pos():")); 15 | posValueLabel = new QLabel(); 16 | // frameGeometry() 17 | frameGeomLabel = new QLabel(tr("frameGeometry():")); 18 | frameGeomValueLabel = new QLabel(); 19 | // geometry() 20 | geomLabel = new QLabel(tr("geometry():")); 21 | geomValueLabel = new QLabel(); 22 | // width() 23 | widthLabel = new QLabel(tr("width():")); 24 | widthValueLabel = new QLabel(); 25 | // height() 26 | heightLabel = new QLabel(tr("height():")); 27 | heightValueLabel = new QLabel(); 28 | // rect() 29 | rectLabel = new QLabel(tr("rect():")); 30 | rectValueLabel = new QLabel(); 31 | // size() 32 | sizeLabel = new QLabel(tr("size():")); 33 | sizeValueLabel = new QLabel(); 34 | 35 | mainLayout = new QGridLayout(this); 36 | mainLayout->addWidget(xLabel,0,0); 37 | mainLayout->addWidget(xValueLabel,0,1); 38 | mainLayout->addWidget(yLabel,1,0); 39 | mainLayout->addWidget(yValueLabel,1,1); 40 | mainLayout->addWidget(posLabel,2,0); 41 | mainLayout->addWidget(posValueLabel,2,1); 42 | mainLayout->addWidget(frameGeomLabel,3,0); 43 | mainLayout->addWidget(frameGeomValueLabel,3,1); 44 | mainLayout->addWidget(geomLabel,4,0); 45 | mainLayout->addWidget(geomValueLabel,4,1); 46 | mainLayout->addWidget(widthLabel,5,0); 47 | mainLayout->addWidget(widthValueLabel,5,1); 48 | mainLayout->addWidget(heightLabel,6,0); 49 | mainLayout->addWidget(heightValueLabel,6,1); 50 | mainLayout->addWidget(rectLabel,7,0); 51 | mainLayout->addWidget(rectValueLabel,7,1); 52 | mainLayout->addWidget(sizeLabel,8,0); 53 | mainLayout->addWidget(sizeValueLabel,8,1); 54 | 55 | updateCoorLabel(); 56 | } 57 | 58 | Coordinate::~Coordinate() 59 | { 60 | } 61 | 62 | void Coordinate::updateCoorLabel() 63 | { 64 | // x() 65 | QString xStr = QString::number(x()); 66 | xValueLabel->setText(xStr); 67 | // y() 68 | QString yStr = QString::number(y()); 69 | yValueLabel->setText(yStr); 70 | // pos() 71 | QString posStrX = QString::number(pos().x()); 72 | QString posStry = QString::number(pos().y()); 73 | posValueLabel->setText(posStrX + "," + posStry); 74 | // frameGeometry() 75 | QString frameStrX = QString::number(frameGeometry().x()); 76 | QString frameStry = QString::number(frameGeometry().y()); 77 | QString frameStrwidth = QString::number(frameGeometry().width()); 78 | QString frameStrheight = QString::number(frameGeometry().height()); 79 | frameGeomValueLabel->setText(frameStrX+","+frameStry+","+frameStrwidth+","+frameStrheight); 80 | // geometry() 81 | QString geomStrX = QString::number(geometry().x()); 82 | QString geomStry = QString::number(geometry().y()); 83 | QString geomStrwidth = QString::number(geometry().width()); 84 | QString geomStrheight = QString::number(geometry().height()); 85 | geomValueLabel->setText(geomStrX+","+geomStry+","+geomStrwidth+","+geomStrheight); 86 | // width() 87 | QString widthStr = QString::number(width()); 88 | widthValueLabel->setText(widthStr); 89 | // height() 90 | QString heightStr = QString::number(height()); 91 | heightValueLabel->setText(heightStr); 92 | // rect() 93 | QString rectStrX = QString::number(rect().x()); 94 | QString rectStry = QString::number(rect().y()); 95 | QString rectStrwidth = QString::number(rect().width()); 96 | QString rectStrheight = QString::number(rect().height()); 97 | rectValueLabel->setText(rectStrX+","+rectStry+","+rectStrwidth+","+rectStrheight); 98 | // size() 99 | QString sizeStrwidth = QString::number(size().width()); 100 | QString sizeStrheight = QString::number(size().height()); 101 | sizeValueLabel->setText(sizeStrwidth + "," + sizeStrheight); 102 | } 103 | 104 | void Coordinate::moveEvent(QMoveEvent *event) 105 | { 106 | updateCoorLabel(); 107 | } 108 | 109 | void Coordinate::resizeEvent(QResizeEvent *event) 110 | { 111 | updateCoorLabel(); 112 | } 113 | 114 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH601/CoordinateExample/coordinate.h: -------------------------------------------------------------------------------- 1 | #ifndef COORDINATE_H 2 | #define COORDINATE_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | class Coordinate : public QDialog 9 | { 10 | Q_OBJECT 11 | 12 | public: 13 | Coordinate(QWidget *parent = nullptr); 14 | ~Coordinate(); 15 | void updateCoorLabel(); // 更新坐标信息 16 | protected: 17 | void moveEvent(QMoveEvent *event) override; // 移动事件响应 18 | void resizeEvent(QResizeEvent *event) override; // 大小调整事件响应 19 | private: 20 | QGridLayout *mainLayout; 21 | // x() 22 | QLabel *xLabel; 23 | QLabel *xValueLabel; 24 | // y() 25 | QLabel *yLabel; 26 | QLabel *yValueLabel; 27 | // pos() 28 | QLabel *posLabel; 29 | QLabel *posValueLabel; 30 | // frameGeometry() 31 | QLabel *frameGeomLabel; 32 | QLabel *frameGeomValueLabel; 33 | // geometry() 34 | QLabel *geomLabel; 35 | QLabel *geomValueLabel; 36 | // width() 37 | QLabel *widthLabel; 38 | QLabel *widthValueLabel; 39 | // height() 40 | QLabel *heightLabel; 41 | QLabel *heightValueLabel; 42 | // rect() 43 | QLabel *rectLabel; 44 | QLabel *rectValueLabel; 45 | // size() 46 | QLabel *sizeLabel; 47 | QLabel *sizeValueLabel; 48 | }; 49 | #endif // COORDINATE_H 50 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH601/CoordinateExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "coordinate.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | Coordinate w; 9 | w.show(); 10 | return a.exec(); 11 | } 12 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/QPainterSimpleExample.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | displayarea.cpp \ 20 | main.cpp \ 21 | qpaintersimpleexample.cpp 22 | 23 | HEADERS += \ 24 | displayarea.h \ 25 | qpaintersimpleexample.h 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | 32 | RESOURCES += \ 33 | Resource.qrc 34 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/Resource.qrc: -------------------------------------------------------------------------------- 1 | 2 | 3 | shape.png 4 | texture.png 5 | 6 | 7 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/displayarea.cpp: -------------------------------------------------------------------------------- 1 | #include "displayarea.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | DisplayArea::DisplayArea(QWidget *parent) : QWidget(parent) 11 | { 12 | // 设置背景 13 | QPalette p = palette(); 14 | p.setColor(QPalette::Window, Qt::white); 15 | setPalette(p); 16 | } 17 | 18 | void DisplayArea::setShape(DisplayArea::Shape shape) 19 | { 20 | this->shape = shape; 21 | update(); // 触发重绘 22 | } 23 | 24 | void DisplayArea::setPen(QPen pen) 25 | { 26 | this->pen = pen; 27 | update(); 28 | } 29 | 30 | void DisplayArea::setBrush(QBrush brush) 31 | { 32 | this->brush = brush; 33 | update(); 34 | } 35 | 36 | void DisplayArea::setFillRule(Qt::FillRule fillRule) 37 | { 38 | this->fillRule = fillRule; 39 | update(); 40 | } 41 | 42 | void DisplayArea::paintEvent(QPaintEvent *event) 43 | { 44 | QPainter p(this); // 新建一个QPainter对象 注意指定parent 45 | p.setPen(pen); // 设置画笔 46 | p.setBrush(brush); // 设置画刷 47 | 48 | // 默认值 49 | static const QPoint point1(50,50); 50 | static const QPoint point2(400,400); // 这里固定了位置,根据实际需要可以通过设置修改 51 | 52 | static const QRect rect(50,50,400,400); 53 | static const QPoint points4[4] = { 54 | QPoint(50, 50), 55 | QPoint(400, 100), 56 | QPoint(450, 350), 57 | QPoint(100, 300) 58 | }; 59 | 60 | static const QPoint points5[5] = { 61 | QPoint(50, 50), 62 | QPoint(400, 100), 63 | QPoint(450, 350), 64 | QPoint(100, 300), 65 | QPoint(200, 250) 66 | }; 67 | int startAngle = 30*16; // 弧形 起始角 QPainter 中画弧形使用的角度值以 1/16度 为单位, 30*16 为 30度 68 | int spanAngle = 120*16; // 弧形 跨度角 69 | 70 | QPainterPath path; 71 | //addRect 将给定的矩形作为闭合的子路径添加到此路径。将该矩形作为一组顺时针的线添加。 72 | // 添加矩形后,绘制路径的当前位置在矩形的左上角。 73 | path.addRect(100, 100, 200, 200); 74 | // 将当前点移动到给定点,隐式开始一个新的子路径并关闭前一个 75 | path.moveTo(0, 0); 76 | // 使用 c1 和 c2 指定的控制点在当前位置和给定端点之间添加三次贝塞尔曲线。 77 | // 添加曲线后,当前位置更新为曲线的终点。 78 | // void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &endPoint) 79 | path.cubicTo(400, 0, 200, 200, 400, 400); 80 | path.cubicTo(0, 400, 200, 200, 0, 0); 81 | path.setFillRule(fillRule); 82 | 83 | switch(shape){ // 根据不同的图形选择进行绘制 84 | case Line:{ // 直线 drawLine() 85 | p.drawLine(point1,point2); // 有不同的实现 86 | break; 87 | } 88 | case Rect:{ // 长方形 drawRect() 89 | p.drawRect(rect); 90 | break; 91 | } 92 | case RoundedRect:{ // 圆角方形 drawRoundRect() 93 | p.drawRoundRect(rect); 94 | break; 95 | } 96 | case Ellipse:{ // 椭圆形 drawEllipse() 97 | p.drawEllipse(rect); 98 | break; 99 | } 100 | case Polygon:{ // 多边形 drawPolygon() 101 | p.drawPolygon(points4,4,fillRule); 102 | break; 103 | } 104 | case Polyline:{ // 多边线 drawPolyline() 105 | p.drawPolyline(points5,5); 106 | break; 107 | } 108 | case Points:{ // 点 drawPoints() 109 | p.drawPoints(points5,5); 110 | break; 111 | } 112 | case Arc:{ // 弧 drawArc() 113 | p.drawArc(rect,startAngle,spanAngle); 114 | break; 115 | } 116 | case Path:{ // 路径 drawPath(const QPainterPath &path) 117 | p.drawPath(path); 118 | break; 119 | } 120 | case Text:{ // 文字 drawText 121 | p.drawText(rect,Qt::AlignCenter,tr("Hello World!")); 122 | break; 123 | } 124 | case PixMap: { // 图片 drawPixmap 125 | p.drawPixmap(50,50,QPixmap(":/shape.png")); 126 | break; 127 | } 128 | default: 129 | break; 130 | } 131 | } 132 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/displayarea.h: -------------------------------------------------------------------------------- 1 | #ifndef DISPLAYAREA_H 2 | #define DISPLAYAREA_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | 9 | class DisplayArea : public QWidget 10 | { 11 | Q_OBJECT 12 | public: 13 | enum Shape{ 14 | Line, // 直线 drawLine() 15 | Rect, // 长方形 drawRect() 16 | RoundedRect, // 圆角方形 drawRoundRect() 17 | Ellipse, // 椭圆形 drawEllipse() 18 | Polygon, // 多边形 drawPolygon() 19 | Polyline, // 多边线 drawPolyline() 20 | Points, // 点 drawPoints() 21 | Arc, // 弧 drawArc() 22 | Path, // 路径 drawPath(const QPainterPath &path) 23 | Text, // 文字 drawText 24 | PixMap, // 图片 drawPixmap 25 | }; 26 | 27 | public: 28 | explicit DisplayArea(QWidget *parent = nullptr); 29 | void setShape(Shape shape); 30 | void setPen(QPen pen); // 画笔 31 | void setBrush(QBrush brush); // 画刷 32 | void setFillRule(Qt::FillRule fillRule); // 填充样式 33 | void paintEvent(QPaintEvent *event) override; // 重绘事件 34 | signals: 35 | private: 36 | Shape shape; // shape类型 37 | QPen pen; // 画笔 38 | QBrush brush; // 画刷 39 | Qt::FillRule fillRule; // 路径和多边形 填充方法 40 | }; 41 | 42 | #endif // DISPLAYAREA_H 43 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/main.cpp: -------------------------------------------------------------------------------- 1 | #include "qpaintersimpleexample.h" 2 | 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | QApplication a(argc, argv); 8 | QPainterSimpleExample w; 9 | w.resize(1200,500); 10 | w.show(); 11 | return a.exec(); 12 | } 13 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/qpaintersimpleexample.h: -------------------------------------------------------------------------------- 1 | #ifndef QPAINTERSIMPLEEXAMPLE_H 2 | #define QPAINTERSIMPLEEXAMPLE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include "displayarea.h" 13 | 14 | class QPainterSimpleExample : public QWidget 15 | { 16 | Q_OBJECT 17 | 18 | public: 19 | QPainterSimpleExample(QWidget *parent = nullptr); 20 | ~QPainterSimpleExample(); 21 | protected slots: 22 | void DisplayShape(int value); // 形状 23 | void DisplayPenColor(); // 画笔颜色 24 | void DisplayPenLineWidth(int value); // 画笔线宽 25 | void DisplayPenStyle(int penStylealue); // 画笔风格 26 | void DisplayPenCap(int penCapValue); // 画笔笔帽 27 | void DisplayPenJoin(int penJoinValue); // 画笔连接点 28 | void DisplayFillStyle(int value); // 填充样式 29 | void DisplaySpreadStyle(int value); // 铺展效果 30 | void DisplayBrushColor(); // 画刷颜色 31 | void DisplayBrushStyle(int value); // 画刷风格 32 | private: 33 | // 绘制显示区 34 | DisplayArea *displayArea; 35 | // 布局 36 | QGridLayout *optiAreaLayout; // 右侧选项区布局 37 | QHBoxLayout *mainLayout; // 主窗口顶层布局 38 | // 形状 39 | QLabel *shapeLabel; 40 | QComboBox *shapeComboBox; 41 | // 画笔颜色 42 | QLabel *penColorLabel; 43 | QFrame *penColorFrame; 44 | QPushButton *penColorBtn; 45 | // 画笔线宽 46 | QLabel *penLineWidthLabel; 47 | QSpinBox *penLineWidthSpinBox; 48 | // 画笔风格 49 | QLabel *penStyleLabel; 50 | QComboBox *penStyleComboBox; 51 | // 画笔笔帽 52 | QLabel *penCapLabel; 53 | QComboBox *penCapComboBox; 54 | // 画笔连接点 55 | QLabel *penJoinLabel; 56 | QComboBox *penJoinComboBox; 57 | // 填充样式 58 | QLabel *fillStyleLabel; 59 | QComboBox *fillStyleComboBox; 60 | // 铺展效果 61 | QLabel *spreadStyleLabel; 62 | QComboBox *spreadStyleComboBox; 63 | QGradient::Spread spread; 64 | // 画刷颜色 65 | QLabel *brushColorLabel; 66 | QFrame *brushColorFrame; 67 | QPushButton *brushColorBtn; 68 | // 画刷风格 69 | QLabel *brushStyleLabel; 70 | QComboBox *brushStyleComboBox; 71 | }; 72 | #endif // QPAINTERSIMPLEEXAMPLE_H 73 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/shape.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH6/CH602/QPainterSimpleExample/shape.png -------------------------------------------------------------------------------- /CodeDemo/CH6/CH602/QPainterSimpleExample/texture.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/CodeDemo/CH6/CH602/QPainterSimpleExample/texture.png -------------------------------------------------------------------------------- /CodeDemo/CH6/CH603/DoubleBufferMechanism/DoubleBufferMechanism.pro: -------------------------------------------------------------------------------- 1 | QT += core gui 2 | 3 | greaterThan(QT_MAJOR_VERSION, 4): QT += widgets 4 | 5 | CONFIG += c++11 6 | 7 | # The following define makes your compiler emit warnings if you use 8 | # any Qt feature that has been marked deprecated (the exact warnings 9 | # depend on your compiler). Please consult the documentation of the 10 | # deprecated API in order to know how to port your code away from it. 11 | DEFINES += QT_DEPRECATED_WARNINGS 12 | 13 | # You can also make your code fail to compile if it uses deprecated APIs. 14 | # In order to do so, uncomment the following line. 15 | # You can also select to disable deprecated APIs only up to a certain version of Qt. 16 | #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 17 | 18 | SOURCES += \ 19 | drawwidget.cpp \ 20 | main.cpp \ 21 | mainwindow.cpp 22 | 23 | HEADERS += \ 24 | drawwidget.h \ 25 | mainwindow.h 26 | 27 | # Default rules for deployment. 28 | qnx: target.path = /tmp/$${TARGET}/bin 29 | else: unix:!android: target.path = /opt/$${TARGET}/bin 30 | !isEmpty(target.path): INSTALLS += target 31 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH603/DoubleBufferMechanism/drawwidget.cpp: -------------------------------------------------------------------------------- 1 | #include "drawwidget.h" 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | DrawWidget::DrawWidget(QWidget *parent) : QWidget(parent) 8 | { 9 | setAutoFillBackground(true); // 背景色 设置 10 | setPalette(QPalette(Qt::white)); // QWidget设置白色为背景 11 | pix = new QPixmap(size()); // 绘图区同尺寸的 pixmap 用于接收绘制内容 12 | pix->fill(Qt::white); // 填充图像背景为白色 13 | setMinimumSize(600,400); // 绘制区窗体最小尺寸 14 | } 15 | 16 | void DrawWidget::mouseMoveEvent(QMouseEvent *event) 17 | { 18 | // 鼠标移动 绘制移动的轨迹 19 | QPainter *painter = new QPainter; // QPainter对象 20 | QPen pen; // QPen 对象 21 | // 设置 pen 的属性 22 | pen.setStyle(style); 23 | pen.setWidth(penWidth); 24 | pen.setColor(color); 25 | // painter 无参数构造,使用 begin 参见 https://blog.csdn.net/kenfan1647/article/details/116266875 26 | painter->begin(pix); // 在调用begin()时,所有绘画工具设置(setPen(),setBrush()等)都将重置为默认值 27 | painter->setPen(pen); 28 | // 绘制从startPos 到鼠标当前位置的直线 29 | painter->drawLine(startPos,event->pos()); // 在 pix 上绘制 30 | painter->end(); 31 | startPos = event->pos(); 32 | update(); // 重绘绘图区 33 | } 34 | 35 | void DrawWidget::mousePressEvent(QMouseEvent *event) 36 | { 37 | this->startPos = event->pos(); // 记录鼠标按下的起始位置 38 | } 39 | 40 | void DrawWidget::paintEvent(QPaintEvent *event) 41 | { 42 | QPainter painter(this); 43 | painter.drawPixmap(QPoint(0,0),*pix); // 绘制 pix 到 绘图区, pix 和 绘图区 同尺寸 44 | } 45 | 46 | void DrawWidget::resizeEvent(QResizeEvent *event) 47 | { 48 | if(width() != pix->width() || height() != pix->height()){ // 尺寸是否改变 49 | QPixmap *newPix = new QPixmap(size()); //新尺寸的 pix 50 | newPix->fill(Qt::white); 51 | QPainter painter(newPix); 52 | painter.drawPixmap(QPoint(0,0),*pix); // 将 图像绘制到新 pix 上 53 | pix = newPix; 54 | } 55 | QWidget::resizeEvent(event); 56 | } 57 | 58 | void DrawWidget::SetPenStyle(Qt::PenStyle style) 59 | { 60 | this->style = style; 61 | } 62 | 63 | void DrawWidget::SetPenWidth(int penWidth) 64 | { 65 | this->penWidth = penWidth; 66 | } 67 | 68 | void DrawWidget::SetPenColor(QColor color) 69 | { 70 | this->color = color; 71 | } 72 | 73 | void DrawWidget::ClearAll() 74 | { 75 | // 将 新的 pix 替代以前的 76 | QPixmap *clearPix = new QPixmap(size()); //新尺寸的 pix 77 | clearPix->fill(Qt::white); 78 | pix = clearPix; 79 | update(); 80 | } 81 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH603/DoubleBufferMechanism/drawwidget.h: -------------------------------------------------------------------------------- 1 | #ifndef DRAWWIDGET_H 2 | #define DRAWWIDGET_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | class DrawWidget : public QWidget 12 | { 13 | Q_OBJECT 14 | public: 15 | explicit DrawWidget(QWidget *parent = nullptr); 16 | void mouseMoveEvent(QMouseEvent *event) override; 17 | void mousePressEvent(QMouseEvent *event) override; 18 | void paintEvent(QPaintEvent *event) override; 19 | void resizeEvent(QResizeEvent *event) override; 20 | public slots: 21 | void SetPenStyle(Qt::PenStyle style); // 画笔风格 22 | void SetPenWidth(int penWidth); // 画笔线宽 23 | void SetPenColor(QColor color); // 画笔颜色 24 | void ClearAll(); // 清空所有 25 | private: 26 | QPixmap *pix; // 绘制的图像 27 | QPoint startPos; 28 | QPoint endPos; 29 | Qt::PenStyle style; 30 | int penWidth; 31 | QColor color; 32 | }; 33 | 34 | #endif // DRAWWIDGET_H 35 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH603/DoubleBufferMechanism/main.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | 3 | #include 4 | #include 5 | 6 | int main(int argc, char *argv[]) 7 | { 8 | QApplication a(argc, argv); 9 | QFont font("楷体"); 10 | a.setFont(font); 11 | MainWindow w; 12 | w.show(); 13 | return a.exec(); 14 | } 15 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH603/DoubleBufferMechanism/mainwindow.cpp: -------------------------------------------------------------------------------- 1 | #include "mainwindow.h" 2 | #include 3 | #include 4 | 5 | MainWindow::MainWindow(QWidget *parent) 6 | : QMainWindow(parent) 7 | { 8 | drawWidget = new DrawWidget; 9 | setCentralWidget(drawWidget); // 设置drawWidget 为中央部件 10 | createToolBar(); // 创建工具条 11 | setMinimumSize(600,400); // 设置主窗口 最小尺寸 与 drawWidget 同步 12 | SetPenStyle(); // 设置画笔style 13 | // 设置 画笔初始线宽 14 | drawWidget->SetPenWidth(penWidthSpinBox->value()); 15 | // 设置 画笔初始颜色 16 | drawWidget->SetPenColor(Qt::black); 17 | } 18 | 19 | MainWindow::~MainWindow() 20 | { 21 | } 22 | 23 | void MainWindow::PenColorSelect() 24 | { 25 | QColor color = QColorDialog::getColor(Qt::black,this); 26 | if(color.isValid()){ 27 | drawWidget->SetPenColor(color); 28 | QPixmap pix(20,20); 29 | pix.fill(color); 30 | penColorBtn->setIcon(QIcon(pix)); 31 | } 32 | } 33 | 34 | void MainWindow::SetPenStyle() 35 | { 36 | drawWidget->SetPenStyle(static_cast(penStyleComboBox-> 37 | itemData(penStyleComboBox->currentIndex(),Qt::UserRole).toInt())); 38 | } 39 | 40 | void MainWindow::createToolBar() 41 | { 42 | toolBar = addToolBar(tr("Tool")); 43 | 44 | // 画笔风格 45 | penStyleLabel = new QLabel(tr("画笔风格:")); 46 | penStyleComboBox = new QComboBox; 47 | penStyleComboBox->addItem(tr("SolidLine"),static_cast(Qt::SolidLine)); 48 | penStyleComboBox->addItem(tr("DashLine"),static_cast(Qt::DashLine)); 49 | penStyleComboBox->addItem(tr("DotLine"),static_cast(Qt::DotLine)); 50 | penStyleComboBox->addItem(tr("DashDotLine"),static_cast(Qt::DashDotLine)); 51 | penStyleComboBox->addItem(tr("DashDotDotLine"),static_cast(Qt::DashDotDotLine)); 52 | penStyleComboBox->addItem(tr("CustomDashLine"),static_cast(Qt::CustomDashLine)); 53 | connect(penStyleComboBox,SIGNAL(activated(int)),this,SLOT(SetPenStyle())); 54 | 55 | // 画笔线宽 56 | penWidthLabel = new QLabel(tr("线宽:")); 57 | penWidthSpinBox = new QSpinBox; 58 | connect(penWidthSpinBox,SIGNAL(valueChanged(int)),drawWidget,SLOT(SetPenWidth(int))); 59 | 60 | // 颜色 选择 61 | penColorBtn = new QToolButton; // 选择按钮 62 | QPixmap pixmap(20,20); 63 | pixmap.fill(Qt::black); 64 | penColorBtn->setIcon(pixmap); 65 | connect(penColorBtn,SIGNAL(clicked()),this,SLOT(PenColorSelect())); 66 | 67 | // 清除按钮 68 | clearBtn = new QToolButton; 69 | clearBtn->setText(tr("清空")); 70 | connect(clearBtn,SIGNAL(clicked()),drawWidget,SLOT(ClearAll())); 71 | 72 | toolBar->addWidget(penStyleLabel); 73 | toolBar->addWidget(penStyleComboBox); 74 | toolBar->addWidget(penWidthLabel); 75 | toolBar->addWidget(penWidthSpinBox); 76 | toolBar->addWidget(penColorBtn); 77 | toolBar->addWidget(clearBtn); 78 | } 79 | 80 | -------------------------------------------------------------------------------- /CodeDemo/CH6/CH603/DoubleBufferMechanism/mainwindow.h: -------------------------------------------------------------------------------- 1 | #ifndef MAINWINDOW_H 2 | #define MAINWINDOW_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include "drawwidget.h" 11 | 12 | class MainWindow : public QMainWindow 13 | { 14 | Q_OBJECT 15 | 16 | public: 17 | MainWindow(QWidget *parent = nullptr); 18 | ~MainWindow(); 19 | public slots: 20 | void PenColorSelect(); // penColorBtn 按钮响应 用于选择颜色 21 | void SetPenStyle(); // 设置画笔style到 中心绘制区 22 | private: 23 | void createToolBar(); // 创建工具条 24 | DrawWidget *drawWidget; // 绘制区 25 | QToolBar *toolBar; 26 | QLabel *penStyleLabel; // 画笔风格 27 | QComboBox *penStyleComboBox; 28 | QLabel *penWidthLabel; // 画笔线宽 29 | QSpinBox *penWidthSpinBox; 30 | QToolButton *penColorBtn; // 画笔颜色选择 31 | QToolButton *clearBtn; 32 | }; 33 | #endif // MAINWINDOW_H 34 | -------------------------------------------------------------------------------- /Pictures/QT基础之GraphicsView图形视图框架介绍/A_QT基础之GraphicsView图形视图框架介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之GraphicsView图形视图框架介绍/A_QT基础之GraphicsView图形视图框架介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之GraphicsView图形视图框架介绍/B_QT基础之GraphicsView图形视图框架介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之GraphicsView图形视图框架介绍/B_QT基础之GraphicsView图形视图框架介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之GraphicsView图形视图框架介绍/C_QT基础之GraphicsView图形视图框架介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之GraphicsView图形视图框架介绍/C_QT基础之GraphicsView图形视图框架介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之GraphicsView图形视图框架介绍/D_QT基础之GraphicsView图形视图框架介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之GraphicsView图形视图框架介绍/D_QT基础之GraphicsView图形视图框架介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之QLayout综合实例/A_QT基础之QLayout综合实例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QLayout综合实例/A_QT基础之QLayout综合实例.png -------------------------------------------------------------------------------- /Pictures/QT基础之QLayout综合实例/B_QT基础之QLayout综合实例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QLayout综合实例/B_QT基础之QLayout综合实例.png -------------------------------------------------------------------------------- /Pictures/QT基础之QLayout综合实例/C_QT基础之QLayout综合实例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QLayout综合实例/C_QT基础之QLayout综合实例.png -------------------------------------------------------------------------------- /Pictures/QT基础之QLayout综合实例/D_QT基础之QLayout综合实例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QLayout综合实例/D_QT基础之QLayout综合实例.png -------------------------------------------------------------------------------- /Pictures/QT基础之QLayout综合实例/E_QT基础之QLayout综合实例.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QLayout综合实例/E_QT基础之QLayout综合实例.png -------------------------------------------------------------------------------- /Pictures/QT基础之QLayout综合实例/布局框架.eddx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QLayout综合实例/布局框架.eddx -------------------------------------------------------------------------------- /Pictures/QT基础之QPalette实例电子时钟/A_QT基础之QPalette实例电子时钟.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QPalette实例电子时钟/A_QT基础之QPalette实例电子时钟.png -------------------------------------------------------------------------------- /Pictures/QT基础之QPalette实例电子时钟/B_QT基础之QPalette实例电子时钟.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QPalette实例电子时钟/B_QT基础之QPalette实例电子时钟.gif -------------------------------------------------------------------------------- /Pictures/QT基础之QPalette类/A_QT基础之QPalette类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QPalette类/A_QT基础之QPalette类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QPalette类/B_QT基础之QPalette类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QPalette类/B_QT基础之QPalette类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QPalette类/C_QT基础之QPalette类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QPalette类/C_QT基础之QPalette类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QPalette类/D_QT基础之QPalette类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QPalette类/D_QT基础之QPalette类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QT5.12下载与安装/A_QT基础之QT5.12下载与安装.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QT5.12下载与安装/A_QT基础之QT5.12下载与安装.png -------------------------------------------------------------------------------- /Pictures/QT基础之QT5.12下载与安装/B_QT基础之QT5.12下载与安装.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QT5.12下载与安装/B_QT基础之QT5.12下载与安装.png -------------------------------------------------------------------------------- /Pictures/QT基础之QT5.12下载与安装/C_QT基础之QT5.12下载与安装.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QT5.12下载与安装/C_QT基础之QT5.12下载与安装.png -------------------------------------------------------------------------------- /Pictures/QT基础之QT5.12下载与安装/D_QT基础之QT5.12下载与安装.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QT5.12下载与安装/D_QT基础之QT5.12下载与安装.png -------------------------------------------------------------------------------- /Pictures/QT基础之QT5.12下载与安装/E_QT基础之QT5.12下载与安装.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QT5.12下载与安装/E_QT基础之QT5.12下载与安装.png -------------------------------------------------------------------------------- /Pictures/QT基础之QToolBox工具盒类/A_QT基础之QToolBox工具盒类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QToolBox工具盒类/A_QT基础之QToolBox工具盒类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QToolBox工具盒类/B_QT基础之QToolBox工具盒类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QToolBox工具盒类/B_QT基础之QToolBox工具盒类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QToolBox工具盒类/C_QT基础之QToolBox工具盒类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QToolBox工具盒类/C_QT基础之QToolBox工具盒类.png -------------------------------------------------------------------------------- /Pictures/QT基础之QToolBox工具盒类/D_QT基础之QToolBox工具盒类.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之QToolBox工具盒类/D_QT基础之QToolBox工具盒类.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/A_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/A_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/B_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/B_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/C_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/C_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/D_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/D_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/E_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/E_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/F_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/F_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/G_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/G_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/H_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/H_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/I_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/I_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/J_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/J_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/K_QT基础之一文介绍QPainter绘制基础图形.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/K_QT基础之一文介绍QPainter绘制基础图形.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍QPainter绘制基础图形/L_QT基础之一文介绍QPainter绘制基础图形.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍QPainter绘制基础图形/L_QT基础之一文介绍QPainter绘制基础图形.gif -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/A_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/A_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/B_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/B_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/C_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/C_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/D_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/D_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/E_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/E_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/F_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/F_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/G_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/G_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/H_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/H_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/I_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/I_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/J_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/J_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.png -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/K_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/K_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/L_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/L_QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式.gif -------------------------------------------------------------------------------- /Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/文本编辑器各类之间的划分与关系.eddx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式/文本编辑器各类之间的划分与关系.eddx -------------------------------------------------------------------------------- /Pictures/QT基础之不规则窗体/A_QT基础之不规则窗体.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之不规则窗体/A_QT基础之不规则窗体.png -------------------------------------------------------------------------------- /Pictures/QT基础之不规则窗体/B_QT基础之不规则窗体.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之不规则窗体/B_QT基础之不规则窗体.png -------------------------------------------------------------------------------- /Pictures/QT基础之不规则窗体/C_QT基础之不规则窗体.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之不规则窗体/C_QT基础之不规则窗体.gif -------------------------------------------------------------------------------- /Pictures/QT基础之主窗口构成/A_QT基础之主窗口构成.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之主窗口构成/A_QT基础之主窗口构成.png -------------------------------------------------------------------------------- /Pictures/QT基础之主窗口构成/B_QT基础之主窗口构成.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之主窗口构成/B_QT基础之主窗口构成.png -------------------------------------------------------------------------------- /Pictures/QT基础之主窗口构成/C_QT基础之主窗口构成.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之主窗口构成/C_QT基础之主窗口构成.png -------------------------------------------------------------------------------- /Pictures/QT基础之主窗口构成/D_QT基础之主窗口构成.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之主窗口构成/D_QT基础之主窗口构成.gif -------------------------------------------------------------------------------- /Pictures/QT基础之位置相关的函数介绍/A_QT基础之位置相关的函数介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之位置相关的函数介绍/A_QT基础之位置相关的函数介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之位置相关的函数介绍/B_QT基础之位置相关的函数介绍.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之位置相关的函数介绍/B_QT基础之位置相关的函数介绍.gif -------------------------------------------------------------------------------- /Pictures/QT基础之位置相关的函数介绍/QT基础之位置相关的函数介绍.eddx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之位置相关的函数介绍/QT基础之位置相关的函数介绍.eddx -------------------------------------------------------------------------------- /Pictures/QT基础之停靠窗口QDockWidget类/A_QT基础之停靠窗口QDockWidget类.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之停靠窗口QDockWidget类/A_QT基础之停靠窗口QDockWidget类.PNG -------------------------------------------------------------------------------- /Pictures/QT基础之停靠窗口QDockWidget类/B_QT基础之停靠窗口QDockWidget类.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之停靠窗口QDockWidget类/B_QT基础之停靠窗口QDockWidget类.PNG -------------------------------------------------------------------------------- /Pictures/QT基础之停靠窗口QDockWidget类/C_QT基础之停靠窗口QDockWidget类.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之停靠窗口QDockWidget类/C_QT基础之停靠窗口QDockWidget类.PNG -------------------------------------------------------------------------------- /Pictures/QT基础之停靠窗口QDockWidget类/D_QT基础之停靠窗口QDockWidget类.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之停靠窗口QDockWidget类/D_QT基础之停靠窗口QDockWidget类.gif -------------------------------------------------------------------------------- /Pictures/QT基础之分割窗口类QSplitter类/A_QT基础之分割窗口类QSplitter类.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之分割窗口类QSplitter类/A_QT基础之分割窗口类QSplitter类.gif -------------------------------------------------------------------------------- /Pictures/QT基础之分割窗口类QSplitter类/B_QT基础之分割窗口类QSplitter类.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之分割窗口类QSplitter类/B_QT基础之分割窗口类QSplitter类.gif -------------------------------------------------------------------------------- /Pictures/QT基础之双缓冲机制介绍/A_QT基础之双缓冲机制介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之双缓冲机制介绍/A_QT基础之双缓冲机制介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之双缓冲机制介绍/B_QT基础之双缓冲机制介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之双缓冲机制介绍/B_QT基础之双缓冲机制介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之双缓冲机制介绍/C_QT基础之双缓冲机制介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之双缓冲机制介绍/C_QT基础之双缓冲机制介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之双缓冲机制介绍/D_QT基础之双缓冲机制介绍.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之双缓冲机制介绍/D_QT基础之双缓冲机制介绍.gif -------------------------------------------------------------------------------- /Pictures/QT基础之双缓冲机制介绍/QT基础之双缓冲机制介绍.eddx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之双缓冲机制介绍/QT基础之双缓冲机制介绍.eddx -------------------------------------------------------------------------------- /Pictures/QT基础之可扩展对话框/A_QT基础之可扩展对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之可扩展对话框/A_QT基础之可扩展对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之可扩展对话框/B_QT基础之可扩展对话框.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之可扩展对话框/B_QT基础之可扩展对话框.gif -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/A_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/A_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/B_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/B_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/C_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/C_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/D_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/D_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/E_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/E_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/F_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/F_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/G_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/G_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本对话框/H_QT基础之基本对话框.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本对话框/H_QT基础之基本对话框.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/A_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/A_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/B_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/B_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/C_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/C_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/D_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/D_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/Demo布局框架.eddx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/Demo布局框架.eddx -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/E_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/E_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/F_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/F_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/G_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/G_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基本布局QLayout/H_QT基础之基本布局QLayout.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基本布局QLayout/H_QT基础之基本布局QLayout.png -------------------------------------------------------------------------------- /Pictures/QT基础之基础进度条/A_QT基础之基础进度条.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基础进度条/A_QT基础之基础进度条.png -------------------------------------------------------------------------------- /Pictures/QT基础之基础进度条/B_QT基础之基础进度条.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之基础进度条/B_QT基础之基础进度条.png -------------------------------------------------------------------------------- /Pictures/QT基础之堆栈窗体QStackedWidget类/A_QT基础之堆栈窗体QStackedWidget类.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之堆栈窗体QStackedWidget类/A_QT基础之堆栈窗体QStackedWidget类.gif -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/A_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/A_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/B_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/B_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/C_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/C_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/D_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/D_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/E_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/E_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/F_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/F_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/G_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/G_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /Pictures/QT基础之常用控件简单介绍/H_QT基础之常用控件简单介绍.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lichangke/QT/8bc160848951a5d99c3526f6b38d1ac6340d3748/Pictures/QT基础之常用控件简单介绍/H_QT基础之常用控件简单介绍.png -------------------------------------------------------------------------------- /QT基础之QPalette实例电子时钟.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 更多参见 4 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 5 | 6 | ### 代码链接 7 | 8 | GitHub链接 :[ClockExample](https://github.com/lichangke/QT/tree/main/CodeDemo/CH4/CH405/ClockExample) 9 | 10 | ### 简介 11 | 12 | 借助`QLCDNumber`实现电子时钟,可以随意拖拽到桌面任意位置,鼠标右键进行关闭,用于实践`QPalette`类、`QTimer`的使用以及`mousePressEvent`\`mouseMoveEvent`\`mouseDoubleClickEvent`事件处理函数的使用。可在此基础上扩展其他应用,参看Qt帮助手册。 13 | 14 | ![B_QT基础之QPalette实例电子时钟](Pictures/QT基础之QPalette实例电子时钟/B_QT基础之QPalette实例电子时钟.gif) 15 | 16 | 17 | 18 | 注意: 19 | 20 | 1、`mouseMoveEvent` 与 `mousePressEvent` 在 区分左右键的方法 21 | 22 | 2、`QLCDNumber` 设置`Flat`才能改变前景色(数字颜色)。 23 | 24 | 3、`QPoint dragOffsetPoint` 的使用 // 保存拖拽鼠标点 相对时钟窗体左上角位置 的偏移值 25 | 26 | ![image-20220519231633903](Pictures/QT基础之QPalette实例电子时钟/A_QT基础之QPalette实例电子时钟.png) 27 | 28 | 29 | 30 | 31 | 32 | ### 代码展示 33 | 34 | **头文件** 35 | 36 | ```cpp 37 | class DigiClock : public QLCDNumber 38 | { 39 | Q_OBJECT 40 | 41 | public: 42 | DigiClock(QWidget *parent = nullptr); 43 | ~DigiClock(); 44 | void mousePressEvent(QMouseEvent *event); // 鼠标按下事件响应函数 45 | void mouseMoveEvent(QMouseEvent *event); // 鼠标移动事件响应函数 46 | void mouseDoubleClickEvent(QMouseEvent *event); // 鼠标双击事件响应函数 47 | public slots: 48 | void showTime(); 49 | private: 50 | int colorIndex; // 颜色序号 51 | QList colorList; // 颜色列表 52 | bool showColonFlag; // 是否显示 :, 模拟闪烁 53 | QPoint dragOffsetPoint; // 保存拖拽鼠标点 相对时钟窗体左上角位置 的偏移值 54 | 55 | }; 56 | ``` 57 | 58 | 59 | 60 | **Cpp文件** 61 | 62 | ```cpp 63 | DigiClock::DigiClock(QWidget *parent) 64 | : QLCDNumber(parent) 65 | { 66 | colorIndex = 0; 67 | colorList = {Qt::darkRed,Qt::darkGreen,Qt::darkBlue, 68 | Qt:: darkCyan,Qt::darkMagenta,Qt::darkYellow,Qt::darkGray}; 69 | //设值参数 70 | this->setWindowFlags(Qt::FramelessWindowHint); // 设置窗体标识,无边框无标题栏 71 | this->setDecMode(); // 十进制 72 | this->setDigitCount(19); //显示个数 73 | this->setWindowOpacity(0.5); // 设置透明度 0 全透明 1 全不透明 74 | this->setSegmentStyle(QLCDNumber::Flat); // flat 才能改变 前景色 75 | this->resize(600,100); // 重设大小 76 | 77 | QPalette p = this->palette(); 78 | p.setColor(QPalette::Window,Qt::lightGray); // 背景色 79 | p.setColor(QPalette::WindowText,colorList.at(colorIndex)); // 前景色 字体颜色 80 | this->setPalette(p); 81 | 82 | QTimer *timer = new QTimer(this); //定时器用于 每秒刷新显示 83 | connect(timer,SIGNAL(timeout()),this,SLOT(showTime())); 84 | timer->start(1000); 85 | this->showTime(); // 初始时间显示 86 | showColonFlag = true; 87 | } 88 | 89 | DigiClock::~DigiClock() 90 | { 91 | } 92 | 93 | void DigiClock::mousePressEvent(QMouseEvent *event) 94 | { 95 | if(event->button() == Qt::LeftButton){ // 注意 mouseMoveEvent 的区别 96 | dragOffsetPoint = event->globalPos() - this->frameGeometry().topLeft(); 97 | event->accept(); 98 | } 99 | if(event->button() == Qt::RightButton){ 100 | close(); // 关闭 101 | } 102 | } 103 | 104 | void DigiClock::mouseMoveEvent(QMouseEvent *event) 105 | { 106 | // 注意这里和 mousePressEvent 的区别,在mouseMoveEvent中 event->button() 始终为 NoButton 107 | if(event->buttons() & Qt::LeftButton){ 108 | move(event->globalPos() - dragOffsetPoint); 109 | event->accept(); 110 | } 111 | } 112 | 113 | void DigiClock::mouseDoubleClickEvent(QMouseEvent *event) 114 | { 115 | if(event->button() == Qt::LeftButton){ 116 | colorIndex++; 117 | if(colorIndex >= colorList.size()){ 118 | colorIndex = 0; 119 | } 120 | QPalette p = this->palette(); 121 | p.setColor(QPalette::WindowText,colorList.at(colorIndex)); // 前景色 字体颜色 122 | this->setPalette(p); 123 | event->accept(); 124 | } 125 | } 126 | 127 | void DigiClock::showTime() 128 | { 129 | QDateTime dateTime = QDateTime::currentDateTime(); 130 | QString text = dateTime.toString("yyyy-MM-dd hh:mm:ss"); // 19个数 131 | if(showColonFlag){ 132 | showColonFlag = false; 133 | text[16] = ':'; 134 | } else { 135 | showColonFlag = true; 136 | text[16] = ' '; 137 | } 138 | this->display(text); // 显示 139 | } 140 | ``` 141 | 142 | 143 | 144 | 在此基础上可以扩展更多应用。 145 | 146 | 147 | 148 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 149 | 150 | -------------------------------------------------------------------------------- /QT基础之QT5.12下载与安装.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | ## QT 下载 4 | 5 | 6 | 7 | QT5.12下载 8 | 9 | [http://www.qtcn.org/bbs/read-htm-tid-1075.html](http://www.qtcn.org/bbs/read-htm-tid-1075.html) 10 | 11 | 我这里选择的是 **Windows Host** 下的 QT 5.12.10 for Windows(3.9GB) 12 | 13 | 也可以通过转存的百度网盘 14 | 15 | 链接:[https://pan.baidu.com/s/1bLQokHK6vmBNzre8Au9mGw](https://pan.baidu.com/s/1bLQokHK6vmBNzre8Au9mGw) 16 | 提取码:0bdc 17 | 18 | ![image-20210711211107739](Pictures/QT基础之QT5.12下载与安装/A_QT基础之QT5.12下载与安装.png) 19 | 20 | 21 | 22 | ## 安装 23 | 24 | 双击 `qt-opensource-windows-x86-5.12.10.exe` 进入安装向导,下一步输入帐号和密码(如果没有可以在官网申请 官网 [https://www.qt.io/](https://www.qt.io/)) 25 | 26 | ![image-20210711212856472](Pictures/QT基础之QT5.12下载与安装/B_QT基础之QT5.12下载与安装.png) 27 | 28 | 29 | 30 | 下一步,设置安装路径 31 | 32 | ![image-20210711213757696](Pictures/QT基础之QT5.12下载与安装/C_QT基础之QT5.12下载与安装.png) 33 | 34 | 35 | 36 | 组件选择,根据需要选择 37 | 38 | 一些介绍 39 | 40 | - MinGW 7.3.0 64-bit 编译器模块。MinGW 是 Minimalist GNU for Windows 的缩写,MinGW是 Windows 平台上使用的 GNU 工具集导入库的集合。采用GCC编译器,据说编译出来的可执行文件运行速度会比其他编译器好 41 | - 用于 windows 平台上的 MSVC 编译器模块,如 msvc2017 32-bit 和 msvc2017 64-bit 等。要安装 MSVC 编译器的模块,需要计算机上已经安装相应版本的 Visual Studio 42 | - 用于 Android 平台的模块,如 Android x86 和 Android ARMv7。如果安装这些组件,就可以构建Android的软件 43 | - Sources 模块是 Qt 的源程序,喜欢阅读源码的朋友或者收藏家们可以选,反正我选了之后一直放在文件夹里吃灰 44 | - Qt Charts 是二维图表模块,用于绘制柱状图、饼图、曲线图等常用二维图表。我的项目正好需要这个,所以我也选了 45 | - Qt Data Visualization 是三维数据图表模块,用于数据的三维显示,如散点的三维空间分布、三维曲面等。 46 | - Qt Purchasing、Qt Virtual Keyboard、Qt WebEngine、Qt Network Auth(TP)等其他模块,括号里的 TP 表示技术预览(Technology Preview)(Purchasing难道是二维码扫码支付?有趣有趣) 47 | - Qt Scritp(Deprecated)是脚本模块,括号里的“Deprecated”表示这是已经过时的模块。 48 | 49 | ![image-20210711214244518](Pictures/QT基础之QT5.12下载与安装/D_QT基础之QT5.12下载与安装.png) 50 | 51 | 52 | 53 | Devoloper and Designer Tools里面,Qt Creator 一定要选。如果前面有选MinGW而主机里没有安装过MinGW的话,应该勾选MinGw这一项。 54 | 55 | ![image-20210711214613135](Pictures/QT基础之QT5.12下载与安装/E_QT基础之QT5.12下载与安装.png) 56 | 57 | 58 | 59 | 选择好之后,点击下一步,勾选同意的复选框,然后下一步。 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 68 | 69 | -------------------------------------------------------------------------------- /QT基础之QVariant类.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | 5 | 更多参见 6 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 7 | 8 | 9 | 10 | QVariant类类似于C++的联合数据类型,既可以保存很多QT类型的值,包括QColor、QBrush、QFont、QPen、QRect、QString和QSize等,也可以存放QT容器类型值 11 | 12 | GitHub链接 :[GitHub](https://github.com/lichangke/QT/tree/main/CodeDemo/CH2/CH206/myVariant) 13 | 14 | ```cpp 15 | QVariant v{709}; 16 | qDebug()<map{{"int",709},{"double",3.14}}; 23 | map["string"] = "Hello World"; 24 | map.insert("color",QColor(255,0,0)); 25 | // 调用相应的转换函数 26 | qDebug()<(); // QVariant(QColor, QColor(ARGB 1, 1, 0, 0)) QColor(ARGB 1, 1, 0, 0) 30 | 31 | QStringList sl; 32 | sl << "A" << "B" << "C" << "D"; 33 | QVariant vt{sl}; 34 | 35 | if(vt.type()==QVariant::StringList) { 36 | auto list = vt.toStringList(); 37 | for (int i=0;i();` `QVariant`变量中保存了一个`QColor`对象,并使用模板`QVariant::value()`还原为`QColor`。 `QVariant`是`QtCOre`模块的类,没有为`QtGui`模块中的数据类型,比如`QColor`、`QImage`、`QPixmap`等提供转换函数,需要使用`QVariant::value()`或者`QVariantValue()` 47 | 48 | `QVariant::type()`函数返回存储在`QVariant`变量中的值得数据类型。`QVariant::StringList`是一个`QVariant::type()`枚举类型的变量。 49 | 50 | 这个枚举可以查看源码`qvariant.h` 51 | 52 | ```cpp 53 | enum Type { 54 | Invalid = QMetaType::UnknownType, 55 | Bool = QMetaType::Bool, 56 | Int = QMetaType::Int, 57 | UInt = QMetaType::UInt, 58 | LongLong = QMetaType::LongLong, 59 | ULongLong = QMetaType::ULongLong, 60 | Double = QMetaType::Double, 61 | Char = QMetaType::QChar, 62 | Map = QMetaType::QVariantMap, 63 | List = QMetaType::QVariantList, 64 | String = QMetaType::QString, 65 | StringList = QMetaType::QStringList, 66 | ByteArray = QMetaType::QByteArray, 67 | BitArray = QMetaType::QBitArray, 68 | Date = QMetaType::QDate, 69 | Time = QMetaType::QTime, 70 | DateTime = QMetaType::QDateTime, 71 | Url = QMetaType::QUrl, 72 | Locale = QMetaType::QLocale, 73 | Rect = QMetaType::QRect, 74 | RectF = QMetaType::QRectF, 75 | Size = QMetaType::QSize, 76 | SizeF = QMetaType::QSizeF, 77 | Line = QMetaType::QLine, 78 | LineF = QMetaType::QLineF, 79 | Point = QMetaType::QPoint, 80 | PointF = QMetaType::QPointF, 81 | RegExp = QMetaType::QRegExp, 82 | RegularExpression = QMetaType::QRegularExpression, 83 | Hash = QMetaType::QVariantHash, 84 | EasingCurve = QMetaType::QEasingCurve, 85 | Uuid = QMetaType::QUuid, 86 | #if QT_CONFIG(itemmodel) 87 | ModelIndex = QMetaType::QModelIndex, 88 | PersistentModelIndex = QMetaType::QPersistentModelIndex, 89 | #endif 90 | LastCoreType = QMetaType::LastCoreType, 91 | 92 | Font = QMetaType::QFont, 93 | Pixmap = QMetaType::QPixmap, 94 | Brush = QMetaType::QBrush, 95 | Color = QMetaType::QColor, 96 | Palette = QMetaType::QPalette, 97 | Image = QMetaType::QImage, 98 | Polygon = QMetaType::QPolygon, 99 | Region = QMetaType::QRegion, 100 | Bitmap = QMetaType::QBitmap, 101 | Cursor = QMetaType::QCursor, 102 | KeySequence = QMetaType::QKeySequence, 103 | Pen = QMetaType::QPen, 104 | TextLength = QMetaType::QTextLength, 105 | TextFormat = QMetaType::QTextFormat, 106 | Matrix = QMetaType::QMatrix, 107 | Transform = QMetaType::QTransform, 108 | Matrix4x4 = QMetaType::QMatrix4x4, 109 | Vector2D = QMetaType::QVector2D, 110 | Vector3D = QMetaType::QVector3D, 111 | Vector4D = QMetaType::QVector4D, 112 | Quaternion = QMetaType::QQuaternion, 113 | PolygonF = QMetaType::QPolygonF, 114 | Icon = QMetaType::QIcon, 115 | LastGuiType = QMetaType::LastGuiType, 116 | 117 | SizePolicy = QMetaType::QSizePolicy, 118 | 119 | UserType = QMetaType::User, 120 | LastType = 0xffffffff // need this so that gcc >= 3.4 allocates 32 bits for Type 121 | }; 122 | ``` 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 131 | 132 | -------------------------------------------------------------------------------- /QT基础之不规则窗体.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 更多参见 4 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 5 | 6 | ### 代码链接 7 | 8 | GitHub链接 :[IrregularShapeExample](https://github.com/lichangke/QT/tree/main/CodeDemo/CH4/CH407/IrregularShapeExample) 9 | 10 | ### 简介 11 | 12 | 常见的对话框窗体是各种方形,但是有时也需要使用非方形的窗体,比如圆形、椭圆形、甚至不规则形状的对话框。这是就要利用`setMask`函数为窗体设置遮罩来实现不规则窗体。设置遮罩后的窗体其尺寸还是原窗体大小,只是被遮罩的地方不可见。 13 | 14 | 注意: 15 | 16 | 1、如何按给出图片形状生成不规则的窗体 17 | 18 | ```cpp 19 | QPixmap pix; 20 | pix.load(":/shape.png"); 21 | resize(pix.size()); // 1、获取图片的size并将图片 22 | setMask(QBitmap(pix.mask()));// 2、设置遮罩 mask() 获取pix图片自身的遮罩 23 | // 此时窗体变为 shape.png 的形状,但是是空白的 24 | ``` 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | ![image-20220521230838292](Pictures/QT基础之不规则窗体/A_QT基础之不规则窗体.png) 33 | 34 | 35 | 36 | 如果不`setMask`将会生成如下窗体 37 | 38 | ![image-20220521231248884](Pictures/QT基础之不规则窗体/B_QT基础之不规则窗体.png) 39 | 40 | 41 | 42 | 2、不要忘记重写`paintEvent`将图片绘制上去 43 | 44 | ```cpp 45 | void ShapeWidget::paintEvent(QPaintEvent *event) 46 | { 47 | // 在窗体上绘制图片 48 | QPainter painter(this); 49 | painter.drawPixmap(0,0,QPixmap(":/shape.png")); 50 | } 51 | ``` 52 | 53 | 54 | 55 | ![C_QT基础之不规则窗体](Pictures/QT基础之不规则窗体/C_QT基础之不规则窗体.gif) 56 | 57 | 58 | 59 | ### 代码展示 60 | 61 | **头文件** 62 | 63 | ```cpp 64 | class ShapeWidget : public QWidget 65 | { 66 | Q_OBJECT 67 | 68 | public: 69 | ShapeWidget(QWidget *parent = nullptr); 70 | ~ShapeWidget(); 71 | protected: 72 | void mouseMoveEvent(QMouseEvent *event) override; 73 | void mousePressEvent(QMouseEvent *event) override; 74 | void paintEvent(QPaintEvent *event) override; 75 | private: 76 | QPoint dragPosition; // 记录拖拽时 鼠标点击位置 与 窗体左上角的 偏移 77 | }; 78 | ``` 79 | 80 | **Cpp文件** 81 | 82 | ```cpp 83 | ShapeWidget::ShapeWidget(QWidget *parent) 84 | : QWidget(parent) 85 | { 86 | QPixmap pix; 87 | pix.load(":/shape.png"); 88 | resize(pix.size()); 89 | setMask(QBitmap(pix.mask()));// 设置遮罩 mask() 获取pix图片自身的遮罩 90 | // 此时窗体变为 shape.png 的形状,但是是空白的 91 | } 92 | 93 | ShapeWidget::~ShapeWidget() 94 | { 95 | } 96 | 97 | void ShapeWidget::mouseMoveEvent(QMouseEvent *event) 98 | { 99 | if(event->buttons() & Qt::LeftButton){ 100 | move(event->globalPos() - dragPosition); 101 | event->accept(); 102 | } 103 | } 104 | 105 | void ShapeWidget::mousePressEvent(QMouseEvent *event) 106 | { 107 | if(event->button() == Qt::LeftButton){ 108 | dragPosition = event->globalPos() - frameGeometry().topLeft(); 109 | event->accept(); 110 | } 111 | if(event->button() == Qt::RightButton){ 112 | close(); 113 | } 114 | } 115 | 116 | void ShapeWidget::paintEvent(QPaintEvent *event) 117 | { 118 | // 在窗体上绘制图片 119 | QPainter painter(this); 120 | painter.drawPixmap(0,0,QPixmap(":/shape.png")); 121 | } 122 | ``` 123 | 124 | 125 | 126 | 127 | 128 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 129 | 130 | -------------------------------------------------------------------------------- /QT基础之信号与槽机制.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | 5 | QT提供了信号与槽机制用于完成界面操作的响应,信号与槽机制是完成任意两个QT对象之间的通信机制。 6 | 7 | **信号(Signal)** 就是在特定情况下被发射的事件,例如PushButton 最常见的信号就是鼠标单击时发射的 clicked() 信号,一个 ComboBox 最常见的信号是选择的列表项变化时发射的 CurrentIndexChanged() 信号。GUI 程序设计的主要内容就是对界面上各组件的信号的响应,只需要知道什么情况下发射哪些信号,合理地去响应和处理这些信号就可以了。 8 | 9 | **槽(Slot)** 就是对信号响应的函数。槽就是一个函数,与一般的C++函数是一样的,可以定义在类的任何部分(public、private 或 protected),可以具有任何参数,也可以被直接调用。槽函数与一般的函数不同的是:槽函数可以与一个信号关联,当信号被发射时,关联的槽函数被自动执行。 10 | 11 | 12 | 13 | ## 信号与槽机制的连接方式 14 | 15 | - **基本格式** 16 | 17 | ```cpp 18 | connect(Object1,SIGNAL(signal1),Object2,SLOT(slot2)); 19 | ``` 20 | 21 | - **一个信号可以和另一个信号相连** 22 | 23 | ```cpp 24 | connect(Object1,SIGNAL(signal1),Object2,SIGNAL(signal2)); 25 | ``` 26 | 27 | Object1的信号1发送可以触发Object2的信号2发送 28 | 29 | 30 | 31 | - **同一个信号可以和多个槽相连** 32 | 33 | ```cpp 34 | connect(Object1,SIGNAL(signal1),Object2,SLOT(slot2)); 35 | connect(Object1,SIGNAL(signal1),Object3,SLOT(slot3)); 36 | ``` 37 | 38 | - **同一个槽可以响应多个信号** 39 | 40 | ```cpp 41 | connect(Object2,SIGNAL(signal2),Object1,SLOT(slot1)); 42 | connect(Object3,SIGNAL(signal3),Object1,SLOT(slot1)); 43 | ``` 44 | 45 | SIGNAL() 和 SLOT()是Qt定义的两个宏,它们返回其参数的C语言风格的字符串(const char*)。因此,下面关联的信号和槽的两个语句是等同的: 46 | 47 | ``` 48 | connect(buttoon, SIGNAL(clicked()), this, SLOT(showArea())); 49 | connect(buttoon, "clicked()", this, "showArea()"); 50 | ``` 51 | 52 | ## 信号与槽机制的优点 53 | 54 | - **类型安全** 55 | 56 | 关联的信号与槽的签名必须是等同的,也就是信号的参数类型和参数个数与接收该信号的槽的参数类型和参数个数相同。不过槽的参数个数可以少于信号的参数个数,但是缺少的参数必须是信号参数的最后一个或多个。 57 | 58 | - **松耦合** 59 | 60 | 信号和槽机制减弱了QT对象的耦合度。激发信号的对象无须知道是哪些对象的哪些槽需要对其相应,也不关心信号有没有被接收到。同样的槽也不知道哪些信号关联了自己。一旦关联信号和槽,QT就保证了适合的槽得到了调用。 61 | 62 | 一个类若要支持信号和槽,就必须从QObject或QObject的之类继承。信号和槽不支持对模板的使用。 63 | 64 | ## 信号与槽机制的效率 65 | 66 | 信号与槽机制增强了对象间通信的灵活性,这也损失了一些性能主要原因如下,但是相比之下这点性能损失是值得的 67 | 68 | - 需要定位接收信号的对象 69 | - 安全地遍历所有的关联(一个信号对多个槽) 70 | - 编组与解组传递的参数 71 | - 在多线程时,信号可能需要排队 72 | 73 | 74 | 75 | 76 | 77 | 78 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 79 | -------------------------------------------------------------------------------- /QT基础之分割窗口QSplitter类.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 更多参见 4 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 5 | 6 | 7 | 8 | ## QSplitter类简介 9 | 10 | `QSplitter` 类实现了一个拆分部件。一个拆分器`splitter`允许用户通过拖动它们之间的边界来控制子部件的大小。任何数量的部件都可以由单个拆分器`splitter`控制。`QSplitter` 的典型用途是创建多个部件并使用 `insertWidget() `或` addWidget() `添加它们。 11 | 12 | 以下示例将并排显示 `QListView`、`QTreeView` 和 `QTextEdit`,并带有两个分隔: 13 | 14 | ```cpp 15 | QSplitter *splitter = new QSplitter(); 16 | QListView *listview = new QListView(); 17 | QTreeView *treeview = new QTreeView(); 18 | QTextEdit *textedit = new QTextEdit(); 19 | splitter->addWidget(listview); 20 | splitter->addWidget(treeview); 21 | splitter->addWidget(textedit); 22 | splitter->setWindowTitle("Splitter Test"); 23 | splitter->show(); 24 | ``` 25 | 26 | ![A_QT基础之分割窗口类QSplitter类](Pictures/QT基础之分割窗口类QSplitter类/A_QT基础之分割窗口类QSplitter类.gif) 27 | 28 | 29 | 30 | 如果在调用 `insertWidget()` 或` addWidget() `时部件已经在 `QSplitter` 中,它将移动到新位置。 这可用于稍后在拆分器中重新排序部件。 可以使用 `indexOf()`、`widget()` 和` count() `来访问拆分器内的小部件。 31 | 32 | 33 | 34 | 默认的 `QSplitter`是 水平(并排)布置其子项如上例; 可以使用 `setOrientation(Qt::Vertical) `将其子项垂直放置。默认情况下,所有部件都可以根据用户的意愿在部件` minimumSizeHint()`(或` minimumSize()`)和 `maximumSize()` 之间或大或小。默认情况下,`QSplitter` 会动态调整其子项的大小。 35 | 36 | 部件之间大小的初始分布是通过将初始大小乘以**拉伸因子**来确定的。 您还可以使用`setSizes() `来设置所有部件的大小。 函数 `size() `返回用户设置的大小。 或者,您可以分别使用` saveState() `和` restoreState()` 从 `QByteArray` 保存和恢复部件的大小。 37 | 38 | 当`hide() `一个子部件时,它的空间将分配给其他子部件。 当您再次 `show() `它时,它将被恢复。 39 | 40 | 41 | 42 | ## 简单Demo和说明 43 | 44 | ![B_QT基础之分割窗口类QSplitter类](Pictures/QT基础之分割窗口类QSplitter类/B_QT基础之分割窗口类QSplitter类.gif) 45 | 46 | Github链接:[Splitter](https://github.com/lichangke/QT/tree/main/CodeDemo/CH3/CH301/Splitter) 47 | 48 | ```cpp 49 | #include "mainwindow.h" 50 | #include 51 | #include 52 | #include 53 | 54 | int main(int argc, char *argv[]) 55 | { 56 | QApplication a(argc, argv); 57 | QFont font("微软雅黑",15); 58 | a.setFont(font); // 设置字体 59 | 60 | // 主分割窗口 61 | // 新建一个 QSplitter 对象 作为主分割窗口,水平分割窗口 62 | QSplitter *splitterMain = new QSplitter(Qt::Horizontal,nullptr); // 水平布置 63 | 64 | // 新建 一个 QTextEdit 对象 并将其加入 主分割窗口中 65 | QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget"),splitterMain); 66 | // QTextEdit *textLeft = new QTextEdit(QObject::tr("Left Widget")); 67 | // splitterMain->addWidget(textLeft); 68 | textLeft->setAlignment(Qt::AlignCenter); // 设置 QTextEdit 对齐方式 AlignCenter 居中对齐 69 | 70 | // 右分割窗口 71 | QSplitter *splitterRight = new QSplitter(Qt::Vertical,splitterMain); // 垂直布置 其父窗口为 splitterMain 72 | // QSplitter *splitterRight = new QSplitter(Qt::Vertical); 73 | // splitterRight->setParent(splitterMain); 74 | 75 | // 调用 setOpaqueResize 用于设定分割窗口的分割条在拖拽是是否实时更新显示。 76 | // true 实时显示,false则拖拽时只显示一条灰色的粗线,拖拽到位并释放鼠标后显示分割条。默认 为true 77 | splitterRight->setOpaqueResize(false); 78 | 79 | 80 | QTextEdit *textTop= new QTextEdit(QObject::tr("Top Widget"),splitterRight); 81 | textTop->setAlignment(Qt::AlignCenter); 82 | QTextEdit *textBottom= new QTextEdit(QObject::tr("Bottom Widget"),splitterRight); 83 | textBottom->setAlignment(Qt::AlignCenter); 84 | 85 | splitterMain->setStretchFactor(1,1); 86 | splitterMain->setWindowTitle(QObject::tr("Splitter Test")); 87 | splitterMain->show(); 88 | 89 | // MainWindow w; 90 | // w.show(); 91 | return a.exec(); 92 | } 93 | ``` 94 | 95 | 96 | 97 | **`QSplitter::setStretchFactor(int index, int stretch)`** 98 | 99 | ```cpp 100 | void QSplitter::setStretchFactor(int index, int stretch) 101 | Updates the size policy of the widget at position index to have a stretch factor of stretch. 102 | stretch is not the effective stretch factor; the effective stretch factor is calculated by taking the initial size of the widget and multiplying it with stretch. 103 | This function is provided for convenience. It is equivalent to 104 | QWidget *widget = splitter->widget(index); 105 | QSizePolicy policy = widget->sizePolicy(); 106 | policy.setHorizontalStretch(stretch); 107 | policy.setVerticalStretch(stretch); 108 | widget->setSizePolicy(policy); 109 | See also setSizes() and widget(). 110 | 111 | ``` 112 | 113 | 更新位置索引处的部件的大小策略以具有拉伸因子。参数`stretch`不是有效拉伸系数; 有效拉伸因子是通过取部件的初始大小并将其乘以拉伸来计算的。 114 | 115 | 位置索引按插入的先后次序从0起依次编号。在这里`setStretchFactor(1,1);`中第一个1是位置索引表示第二个插入`splitterMain`的·部件也就是`splitterRight`,第二个1表示此控件也就是`splitterMain`可伸缩控件。也就是当整个对话框的宽度发生改变时,左部分的文件编辑框宽度保持不变,右部分的分割窗口宽度随整个对话框大小的改变进行调整。 116 | 117 | 118 | 119 | 120 | 121 | 122 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 123 | 124 | -------------------------------------------------------------------------------- /QT基础之可扩展对话框.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 更多参见 4 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 5 | 6 | ### 代码链接 7 | 8 | GitHub链接 :[ExtensibleDialogExample](https://github.com/lichangke/QT/tree/main/CodeDemo/CH4/CH406/ExtensibleDialogExample) 9 | 10 | ### 简介 11 | 12 | 扩展对话框通常情况下,只是出现基本对话框,可通过某种方式切换显示完整的对话框窗体,一般情况下通过一个按钮实现。 13 | 14 | 注意: 15 | 16 | 1、需要设置对话框的尺寸保持相对固定,确保扩展对话框在扩展隐藏后能恢复到初始状态。 17 | 18 | `void setSizeConstraint(QLayout::SizeConstraint)` 设置布局调整大小的模式 19 | 20 | ![image-20220520233338013](Pictures/QT基础之可扩展对话框/A_QT基础之可扩展对话框.png) 21 | 22 | 参见Qt帮助手册 23 | 24 | 例子默认情况下只显示基础信息部分,通过一个按钮来展示或者隐藏扩展的部分。 25 | 26 | 27 | 28 | ### 代码展示 29 | 30 | ![B_QT基础之可扩展对话框](Pictures/QT基础之可扩展对话框/B_QT基础之可扩展对话框.gif) 31 | 32 | **头文件** 33 | 34 | ```cpp 35 | class ExtensibleDlg : public QDialog 36 | { 37 | Q_OBJECT 38 | 39 | public: 40 | ExtensibleDlg(QWidget *parent = nullptr); 41 | ~ExtensibleDlg(); 42 | private slots: 43 | void showDetailInfoPart(); // 按钮响应用于 显示隐藏 扩展部分 44 | private: 45 | void CreateBaseInfoPart(); // 创建基础信息部分 46 | void CreateDetailInfoPart(); // 创建扩展的细节信息部分 47 | QWidget *baseInfoPart; // 础信息部分 48 | QWidget *detailInfoPart; // 细节信息部分 49 | QVBoxLayout *mainLayout; // 布局 50 | }; 51 | ``` 52 | 53 | 54 | 55 | **Cpp文件** 56 | 57 | ```cpp 58 | ExtensibleDlg::ExtensibleDlg(QWidget *parent) 59 | : QDialog(parent) 60 | { 61 | setWindowTitle(tr("Extension Dialog Example")); 62 | CreateBaseInfoPart(); 63 | CreateDetailInfoPart(); 64 | mainLayout = new QVBoxLayout(this); 65 | mainLayout->addWidget(baseInfoPart); 66 | mainLayout->addWidget(detailInfoPart); 67 | mainLayout->setSizeConstraint(QLayout::SetFixedSize); // 设置窗体大小固定,不能通过拖拽改变大小 68 | } 69 | 70 | ExtensibleDlg::~ExtensibleDlg() 71 | { 72 | } 73 | 74 | void ExtensibleDlg::showDetailInfoPart() 75 | { 76 | if(detailInfoPart->isHidden()){ 77 | detailInfoPart->show(); 78 | } else { 79 | detailInfoPart->hide(); 80 | } 81 | } 82 | 83 | void ExtensibleDlg::CreateBaseInfoPart() 84 | { 85 | baseInfoPart = new QWidget; 86 | // 控件 87 | QLabel *nameLabel = new QLabel(tr("姓名:")); 88 | QLineEdit *nameLineEdit = new QLineEdit; 89 | QLabel *sexLabel = new QLabel(tr("性别:")); 90 | QComboBox *sexComboBox = new QComboBox; 91 | sexComboBox->addItem(tr("男")); 92 | sexComboBox->addItem(tr("女")); 93 | QPushButton *okBtn = new QPushButton(tr("确定")); 94 | QPushButton *detailBtn = new QPushButton(tr("详细")); 95 | // 信号槽 96 | connect(detailBtn,SIGNAL(clicked()),this,SLOT(showDetailInfoPart())); 97 | // 布局 98 | QGridLayout *baseInfoLayout = new QGridLayout(baseInfoPart); 99 | baseInfoLayout->addWidget(nameLabel,0,0); 100 | baseInfoLayout->addWidget(nameLineEdit,0,1); 101 | baseInfoLayout->addWidget(okBtn,0,2); 102 | baseInfoLayout->addWidget(sexLabel,1,0); 103 | baseInfoLayout->addWidget(sexComboBox,1,1); 104 | baseInfoLayout->addWidget(detailBtn,1,2); 105 | baseInfoLayout->setSpacing(10); 106 | } 107 | 108 | void ExtensibleDlg::CreateDetailInfoPart() 109 | { 110 | detailInfoPart = new QWidget; 111 | QLabel *ageLabel = new QLabel(tr("年龄:")); 112 | QLineEdit *ageLineEdit = new QLineEdit; 113 | QLabel *departmentLabel = new QLabel(tr("部门:")); 114 | QComboBox *departmentComboBox = new QComboBox; 115 | departmentComboBox->addItem(tr("部门1")); 116 | departmentComboBox->addItem(tr("部门2")); 117 | QLabel *emailLabel = new QLabel(tr("Email:")); 118 | QLineEdit *emailLineEdit = new QLineEdit; 119 | // 布局 120 | QGridLayout *detailInfoLayout = new QGridLayout(detailInfoPart); 121 | detailInfoLayout->addWidget(ageLabel,0,0); 122 | detailInfoLayout->addWidget(ageLineEdit,0,1); 123 | detailInfoLayout->addWidget(departmentLabel,1,0); 124 | detailInfoLayout->addWidget(departmentComboBox,1,1); 125 | detailInfoLayout->addWidget(emailLabel,2,0); 126 | detailInfoLayout->addWidget(emailLineEdit,2,1); 127 | detailInfoPart->hide(); // 一开始隐藏 128 | } 129 | ``` 130 | 131 | 132 | 133 | 134 | 135 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 136 | 137 | -------------------------------------------------------------------------------- /QT基础之基础进度条.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | 5 | 更多参见 6 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 7 | 8 | 9 | 10 | ### 代码链接 11 | 12 | GitHub链接 :[ProgressExample](https://github.com/lichangke/QT/tree/main/CodeDemo/CH4/CH403/ProgressExample) 13 | 14 | 15 | 16 | ### 介绍 17 | 18 | 在长时间任务中需要提供进度条用于显示进度。进度条对话框有两种使用方法,模态方式和非模态方式。 19 | 20 | Qt提供了两种显示进度条的方式:一种是`QProgressBar`,提供一种横向或纵向显示进度的控件表示方式,来描述任务的完成情况;另一种是`QProgressDialog`,提供一种针对慢速过程的进度对话框表示方式,用于描述任务的完成情况。标准的进度条对话框包括一个进度显示条、一个取消按钮以及一个标签。 21 | 22 | 23 | 24 | ![image-20220517224524026](Pictures/QT基础之基础进度条/A_QT基础之基础进度条.png) 25 | 26 | 27 | 28 | ![image-20220517224655238](Pictures/QT基础之基础进度条/B_QT基础之基础进度条.png) 29 | 30 | 31 | 32 | ### 代码展示 33 | 34 | **头文件** 35 | 36 | ```cpp 37 | class ProgressDlg : public QDialog 38 | { 39 | Q_OBJECT 40 | 41 | public: 42 | ProgressDlg(QWidget *parent = nullptr); 43 | ~ProgressDlg(); 44 | private slots: 45 | void startProgress(); 46 | private: 47 | QLabel *fileNumLabel; 48 | QLineEdit *fileNumLineEdit; 49 | QLabel *progressType; 50 | QComboBox *typeComboBox; 51 | QProgressBar *progressBar; 52 | QPushButton *startBtn; 53 | QGridLayout *mainLayout; 54 | }; 55 | ``` 56 | 57 | **Cpp文件** 58 | 59 | ```cpp 60 | ProgressDlg::ProgressDlg(QWidget *parent) 61 | : QDialog(parent) 62 | { 63 | setWindowTitle(tr("ProgressExample")); 64 | fileNumLabel = new QLabel(); 65 | fileNumLabel->setText(tr("文件数目:")); 66 | fileNumLineEdit = new QLineEdit; 67 | fileNumLineEdit->setText(tr("1000000")); 68 | progressType = new QLabel; 69 | progressType->setText(tr("显示类型")); 70 | typeComboBox = new QComboBox; 71 | typeComboBox->addItem(tr("QProgressBar")); 72 | typeComboBox->addItem(tr("QProgressDialog")); 73 | progressBar = new QProgressBar; 74 | startBtn = new QPushButton; 75 | startBtn->setText(tr("开始")); 76 | 77 | mainLayout = new QGridLayout(this); 78 | mainLayout->addWidget(fileNumLabel,0,0); 79 | mainLayout->addWidget(fileNumLineEdit,0,1); 80 | mainLayout->addWidget(progressType,1,0); 81 | mainLayout->addWidget(typeComboBox,1,1); 82 | mainLayout->addWidget(progressBar,2,0,1,2); 83 | mainLayout->addWidget(startBtn,3,1); 84 | mainLayout->setMargin(15); 85 | mainLayout->setSpacing(10); 86 | 87 | connect(startBtn,SIGNAL(clicked()),this,SLOT(startProgress())); 88 | } 89 | 90 | ProgressDlg::~ProgressDlg() 91 | { 92 | } 93 | 94 | void ProgressDlg::startProgress() 95 | { 96 | bool ok = false; 97 | int num = fileNumLineEdit->text().toInt(&ok); 98 | if(ok){ 99 | int index = typeComboBox->currentIndex(); 100 | if(index == 0){// 选择了 QProgressBar 101 | startBtn->setDisabled(true); 102 | // QProgressBar 有几个重要属性 103 | // 1、minimum\maximum: 决定进度条指示的最小值和最大值 104 | // 2、format: 决定进度条显示文字的格式。`%p%` 显示完成百分比,默认方式; `%v`显示当前进度值; `%m`显示总的步进值 105 | // 3、invertedAppearance : 反向显示 106 | progressBar->setRange(0,num); 107 | progressBar->setFormat("%p%"); // %p%[0%-100%] %v[0-num] %m 108 | progressBar->setInvertedAppearance(false); 109 | for (int i = 1; isetValue(i); 111 | } 112 | startBtn->setDisabled(false); 113 | } else if(index == 1){ 114 | // QProgressDialog几个重要属性 115 | // 1、minimum\maximum: 决定进度条指示的最小值和最大值 116 | // 2、minimumDuration: 进度条显示等待时间,系统会根据工作量预估,若大于则显示,若小于不显示 117 | QProgressDialog *progressDlg = new QProgressDialog; 118 | progressDlg->setWindowModality(Qt::WindowModal); // 设置模态显示 119 | progressDlg->setMinimumDuration(1); // 默认4秒 120 | progressDlg->setRange(0,num); 121 | progressDlg->setWindowTitle(tr("Please Waiting...")); 122 | progressDlg->setLabelText(tr("Coping....")); 123 | progressDlg->setCancelButtonText(tr("Cancel")); 124 | for (int i = 1; isetValue(i); 126 | if(progressDlg->wasCanceled()){ 127 | return; 128 | } 129 | } 130 | } 131 | } 132 | } 133 | ``` 134 | 135 | 136 | 137 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 138 | 139 | -------------------------------------------------------------------------------- /QT基础之堆栈窗体QStackedWidget类.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 更多参见 4 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 5 | 6 | 7 | 8 | ## QStackedWidget类简介 9 | 10 | `QStackedWidget `类提供了一堆部件,一次只能看到其中一个部件。`QStackedWidget` 可用于创建类似于` QTabWidget` 提供的用户界面。它是一个构建在 `QStackedLayout `类之上的便捷布局部件。 11 | 12 | 与 `QStackedLayout` 一样,`QStackedWidget` 可以构造并填充多个子部件(“页面”)。 13 | 14 | ```cpp 15 | QLabel *firstOageWidget = new QLabel(tr("firstOageWidget")); // 可以是其他 widget 16 | QLabel *secondPageWidget = new QLabel(tr("secondPageWidget")); 17 | QLabel *thirdPageWidget = new QLabel(tr("thirdPageWidget")); 18 | QStackedWidget *stackedWidget = new QStackedWidget(this); 19 | stackedWidget->addWidget(firstOageWidget); 20 | stackedWidget->addWidget(secondPageWidget); 21 | stackedWidget->addWidget(thirdPageWidget); 22 | QVBoxLayout *layout = new QVBoxLayout; 23 | layout->addWidget(stackedWidget); 24 | setLayout(layout); 25 | ``` 26 | 27 | `QStackedWidget` 没有为用户提供切换页面的内在方法。 这通常通过存储 `QStackedWidget` 页面标题的 `QComboBox` 或 `QListWidget` 来完成。 28 | 29 | ```cpp 30 | QComboBox *pageComboBox = new QComboBox(); 31 | pageComboBox->addItem(tr("Page 1")); 32 | pageComboBox->addItem(tr("Page 2")); 33 | pageComboBox->addItem(tr("Page 3")); 34 | connect(pageComboBox, SIGNAL(activated(int)),stackedWidget, SLOT(setCurrentIndex(int))); 35 | ``` 36 | 37 | 填充堆叠部件时,部件将添加到内部列表中。` indexOf()` 函数返回该列表中部件的索引。部件可以使用 `addWidget()` 函数添加到列表的末尾,也可以使用` insertWidget() `函数插入到给定的索引处。`removeWidget() `函数从堆叠部件中删除部件。可以使用 `count() `函数获取堆叠部件中包含的部件数量。 38 | 39 | 40 | 41 | ## 简单Demo和说明 42 | 43 | 在实际应用中,`QStackedWidget`多与列表框`QListWidget`及下拉表框`QComboBox`配合使用。 44 | 45 | ![A_QT基础之堆栈窗体QStackedWidget类](Pictures/QT基础之堆栈窗体QStackedWidget类/A_QT基础之堆栈窗体QStackedWidget类.gif) 46 | 47 | GitHub链接 :[StackDlg](https://github.com/lichangke/QT/tree/main/CodeDemo/CH3/CH303/StackDlg) 48 | 49 | ```cpp 50 | setWindowTitle(tr("QT基础之堆栈窗体QStackedWidget类")); 51 | // 创建 一个 QListWidget 控件对象 ,用于同 QStackedWidget 关联 52 | list = new QListWidget(); 53 | list->addItem(tr("List 1")); 54 | list->addItem(tr("List 2")); 55 | list->addItem(tr("List 3")); 56 | 57 | 58 | // 创建 三个 QLabel 标签控件对象,作为堆栈窗口需要显示的三层窗体 59 | label1 = new QLabel(tr("WindowTest1")); 60 | label2 = new QLabel(tr("WindowTest2")); 61 | label3 = new QLabel(tr("WindowTest3")); 62 | 63 | // 创建 QStackedWidget 堆栈窗体对象 64 | stackedWidget = new QStackedWidget(this); 65 | // 将 三个 QLabel 标签控件对象 插入 QStackedWidget 66 | stackedWidget->addWidget(label1); 67 | stackedWidget->addWidget(label2); 68 | stackedWidget->addWidget(label3); 69 | // 创建 布局 70 | QHBoxLayout *layout = new QHBoxLayout(this);// 水平布局 71 | 72 | layout->setMargin(5); // 对话框或窗体 边距 5 73 | layout->setSpacing(5); // 各个控件之间的间距 5 74 | layout->addWidget(list); 75 | layout->addWidget(stackedWidget,5,Qt::AlignCenter); 76 | layout->setStretchFactor(list,1); // 设定可伸缩控件 77 | layout->setStretchFactor(stackedWidget,3); 78 | connect(list, SIGNAL(currentRowChanged(int)),stackedWidget, SLOT(setCurrentIndex(int))); 79 | ``` 80 | 81 | 82 | 83 | 84 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 85 | 86 | -------------------------------------------------------------------------------- /QT基础之容器类.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | 5 | 6 | 7 | QT提供了一组通用的基于模板的容器类。存储在QT容器类中数据必须是可赋值的数据类型,也就是说,这种数据类型必须提供一个默认的构造函数、一个复制构造函数和一个赋值操作运算符。这样的数据类型包含了通常使用的大多数数据类型,包括基本数据类型(如int和double等)和QT的一些数据类型(如QString、QDate和QTime等),但QT的`QObject`及其他的子类(如`QWidget QDialog`等)不能够存储在容器中,可以存储`QObject`及其他的子类的指针 8 | 9 | ```cpp 10 | QList list; // 无法通过编译 11 | QList list; // 通过编译 12 | ``` 13 | 14 | QT容器类是可以嵌套的 15 | 16 | ```cpp 17 | QHash> 18 | ``` 19 | 20 | 21 | 22 | ## QList类、QLinkedList类和QVector类 23 | 24 | 25 | 26 | ### QList类 27 | 28 | `QList`是最常用的容器类,它存储给定数据类型`T`的一列数值。继承自`QList` 的子类有 `QByteArrayList, QItemSelection, QQueue, and QStringList`等。 29 | 30 | `QList`维护了一个指针数组,该数组存储的指针指向`QList`存储的列表项的内容。因此,`QList`支持基于下标的快速访问。 31 | 32 | 对于不同数据类型,`QList`采取不同的存储策略。 33 | 34 | (1)如果`T`是一个指针或者指针大小的基本类型(占用字节数相同),`QList`会将数值直接存储在它的数组中 35 | 36 | (2)如果`QList`存储对象的指针,则该指针指向实际存储的对象 37 | 38 | 39 | 40 | ### QLinkedList类 41 | 42 | `QLinkedList`是一个链式列表,以非连续的内存存储数据,不能使用下标只能使用迭代器访问数据项 43 | 44 | ### QVector类 45 | 46 | `QVector`在相邻的内存中存储给定数据类型`T`的一组数值。在`QVector`的前部或中部位置进行插入操作的速度很慢,因为会存在大量的数据搬移操作。`QLinkedList`既可以使用下标访问数据项,也可以使用迭代器访问数据项。 47 | 48 | ### STL风格迭代器遍历容器 49 | 50 | | 容器类 | 只读迭代器 | 读写迭代器 | 51 | | :----------------------: | :------------------------------: | :------------------------: | 52 | | `QList`,`QQueue` | `QList::const_iterator` | `QList::iterator` | 53 | | `QLinkedList` | `QLinkedList::const_iterator` | `QLinkedList::iterator` | 54 | | `QVector`,`QStack` | QVector::const_iterator | `QVector::iterator` | 55 | 56 | GitHub链接: [GitHub ](https://github.com/lichangke/QT/tree/main/CodeDemo/CH2/CH203/STL_Iterator) 57 | 58 | ```cpp 59 | #include 60 | #include 61 | 62 | int main(int argc, char *argv[]) 63 | { 64 | QApplication a(argc, argv); 65 | 66 | QList list; 67 | for(int j=0; j<10; j++){ 68 | list.append(j); 69 | } 70 | 71 | QList::iterator i; 72 | for(i=list.begin();i!=list.end();++i){ 73 | qDebug() << (*i); 74 | *i = (*i) * 10; 75 | } 76 | 77 | QList::const_iterator ci; 78 | for(ci = list.constBegin();ci!=list.constEnd();++ci){ 79 | qDebug() << (*ci); 80 | } 81 | 82 | return a.exec(); 83 | } 84 | ``` 85 | 86 | 87 | 88 | ## QMap类和QHash类 89 | 90 | `QMap`类和`QHash`类具有很多类似的功能,但也有差别: 91 | 92 | - `QHash`有比`QMap`更快的查找速度 93 | - `QHash`以任意顺序存储数据项,而`QMap`总是按照键 `Key`的顺序存储数据 94 | - `QHash`的键类型 `Key`必须提供`operator==()`和一个全局的`qHash(Key)`函数,而`QMap`的键类型 `Key`必须提供`operator<=()`函数 95 | 96 | 97 | 98 | ### QMap类 99 | 100 | `QMap`提供一个从类型为`Key`的键到类型为`T`的值得映射。 101 | 102 | ### QHash类 103 | 104 | `QHash`具有与`QMap`几乎完全相同的API。`QHash`维护一张哈希表,其大小与`QHash`数据项数目相适应 105 | 106 | ### STL风格迭代器遍历容器 107 | 108 | | 容器类 | 只读迭代器 | 读写迭代器 | 109 | | :---------------------------------: | :----------------------------------------------------------: | :----------------------: | 110 | | `QMap`,`QMultiMap` | `QMap::const_iterator` | `QMap::iterator` | 111 | | `QHash`,`QMultiHash` | `QHash`,`QMultiHash``QHash::const_iterator` | `QHash::iterator` | 112 | 113 | GitHub链接: [GitHub](https://github.com/lichangke/QT/tree/main/CodeDemo/CH2/CH205/STL_Iterator) 114 | 115 | ```cpp 116 | #include 117 | #include 118 | int main(int argc, char *argv[]) 119 | { 120 | QApplication a(argc, argv); 121 | QMap map; 122 | map.insert("abc","123"); 123 | map.insert("def","456"); 124 | map.insert("hij","789"); 125 | 126 | QMap::const_iterator ci; 127 | for(ci=map.constBegin();ci!=map.constEnd();ci++){ 128 | qDebug() << "Key = " << ci.key() << ", Value = " << ci.value(); 129 | } 130 | 131 | QMap::iterator i; 132 | i = map.find("abc"); 133 | if(i!=map.end()){ 134 | i.value() = "000"; 135 | } 136 | qDebug() << "------------"; 137 | QMap::const_iterator ci2; 138 | for(ci2=map.constBegin();ci2!=map.constEnd();ci2++){ 139 | qDebug() << "Key = " << ci2.key() << ", Value = " << ci2.value(); 140 | } 141 | 142 | return a.exec(); 143 | } 144 | ``` 145 | 146 | 147 | 148 | 149 | 150 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 151 | 152 | -------------------------------------------------------------------------------- /QT基础之常用控件简单介绍.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 更多参见 4 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 5 | 6 | 7 | 8 | ## 按钮组(Buttons) 9 | 10 | 11 | 12 | ![image-20210714215851783](Pictures/QT基础之常用控件简单介绍/A_QT基础之常用控件简单介绍.png) 13 | 14 | - `Push Button` :按钮 15 | - `Tool Button` :工具按钮 16 | - `Radio Button` :单选按钮 17 | - `Check Button` :复选框 18 | - `Command Link Button` :命令链接按钮 19 | - `Dialog Button Box` :对话框按钮盒 20 | 21 | 22 | 23 | ## 输入部件组(Input Widgets) 24 | 25 | 26 | 27 | ![image-20210714220435643](Pictures/QT基础之常用控件简单介绍/B_QT基础之常用控件简单介绍.png) 28 | 29 | 30 | 31 | - `Combo Box`:组合框 32 | - `Font Combo Box`:字体组合框 33 | - ` Line Edit`:行编辑框 34 | - `Text Edit`:文本编辑框 35 | - `Plain Text Edit`:纯文本编辑框 36 | - `Spin Box`:数字显示框(旋转盒) 37 | - `Double Spin Box`:Double 数字显示框 38 | - `Time Edit`:时间编辑 39 | - `Date Edit`:日期编辑 40 | - `Date/Time Edit `:日期/时间编辑 41 | - `Dial`:拨号 42 | - `Horizontal Scroll Bar`:水平滚动条 43 | - `Vertical Scroll Bar `:垂直滚动条 44 | - `Horizontal Slider`:水平滑块 45 | - `Vertical Slider `:垂直滑块 46 | - `Key Sequence Edit`:按键序列编辑框 47 | 48 | 49 | 50 | ## 显示控件组(Display Widgets) 51 | 52 | 53 | 54 | ![image-20210714221655623](Pictures/QT基础之常用控件简单介绍/C_QT基础之常用控件简单介绍.png) 55 | 56 | 57 | 58 | - `Label`:标签 59 | 60 | - `Text Browser`:文本浏览器 61 | - ` Graphics View`:图形视图 62 | - ` Calendar Widget`:日历 63 | - ` LCD Number`:液晶数字 64 | - `Progress Bar `:进度条 65 | - `Horizontal Line `:水平线 66 | - ` Vertical Line`:垂直线 67 | - `OpenGL Widget `:OpenGL 工具 68 | - ` QQuickWidget`:嵌入QML工具 69 | 70 | ## 空间间隔组(Spacers) 71 | 72 | ![image-20210714222222782](Pictures/QT基础之常用控件简单介绍/D_QT基础之常用控件简单介绍.png) 73 | 74 | - `Horizontal Spacer `:水平间隔 75 | - `Vertical Spacer`:垂直间隔 76 | 77 | 78 | 79 | ## 布局管理组(Layouts) 80 | 81 | ![image-20210714222509305](Pictures/QT基础之常用控件简单介绍/E_QT基础之常用控件简单介绍.png) 82 | 83 | 84 | 85 | - `Vertical Layout `:垂直布局 86 | - `Horizontal Layout`:水平布局 87 | - `Grid Layout`:网格布局 88 | - `Form Layout`:表单布局 89 | 90 | ## 容器组(Containers) 91 | 92 | ![image-20210714222823857](Pictures/QT基础之常用控件简单介绍/F_QT基础之常用控件简单介绍.png) 93 | 94 | 95 | 96 | - `Group Box`:组框 97 | - `Scroll Area`:滚动区域 98 | - `Tool Box`:工具箱 99 | - `Tab Widget`:标签部件 100 | - `Stacked Widget`:堆叠部件 101 | - `Frame`:框架 102 | - `Widget`:小部件 103 | - `MDI Area`:MDI区域 104 | - `Dock Widget`:停靠窗体部件 105 | - `QAxWidget`:封装Flash的ActiveX控件 106 | 107 | 108 | 109 | ## 项目视图组(Item Views) 110 | 111 | ![image-20210714223543448](Pictures/QT基础之常用控件简单介绍/G_QT基础之常用控件简单介绍.png) 112 | 113 | 114 | 115 | - `List View`:列表视图 116 | - `Tree View`:树形视图 117 | 118 | - `Table View`:表格式图 119 | 120 | - `Column View`:列视图 121 | 122 | - `Undo View`:撤消视图 123 | 124 | 125 | 126 | ## 项目控件组(Item Widgets) 127 | 128 | ![image-20210714223958111](Pictures/QT基础之常用控件简单介绍/H_QT基础之常用控件简单介绍.png) 129 | 130 | 131 | 132 | - `List Widget`:列表控件 133 | - `Tree Widget`:树形控件 134 | - `Table Widget`:表格控件 135 | 136 | 137 | 138 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 139 | 140 | -------------------------------------------------------------------------------- /QT基础之隐式共享.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | 4 | 5 | 更多参见 6 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 7 | 8 | 9 | 10 | 隐式共享又称为`copy on write`回写复制。当两个对象共享同一份数据(浅拷贝实现数据块的共享)时,如果数据不变就不进行数据的复制,而当某个对象需要改变数据时则执行深拷贝。 11 | 12 | - 深拷贝 : 即就是生成对象的一个完整的复制品; 13 | 14 | - 浅拷贝:只是一个引用复制(比如仅仅复制指向共享数据的指针)。 15 | 16 | 隐式共享可以降低对内存和CPU资源的使用,提高程序的运行效率。使用隐式共享能使得在函数中(eg. 参数、返回值)使用值传递更有效率。 QString采用隐式共享技术,将深拷贝和浅拷贝很好地结合了起来。 17 | 18 | 19 | 20 | ```cpp 21 | QString str1 = "ubuntu"; 22 | QString str2 = str1; // 发生一次浅拷贝 str1 str2指向同一个数据结构,引用计数器值为2 23 | qDebug() << "str1 = " << str1; // str1 = "ubuntu" 24 | qDebug() << "str2 = " << str2; // str2 = "ubuntu" 25 | 26 | // 对 QString对象str2修改导致一次深拷贝,str2指向一个新的与str1指向不同的数据结构其引用计数值为1,str1指向的数据结构引用计数器值减1后为1 27 | str2[2] = 'm'; 28 | str2[0] = 'o'; 29 | qDebug() << "str1 = " << str1; // str1 = "ubuntu" 30 | qDebug() << "str2 = " << str2; // str2 = "obmntu" 31 | 32 | // str2赋值给str1,str1原指向的数据结构的引用数修改为0,也就是没有对象使用这个数据结构会从内存中释放 33 | // 操作结束后,str1 str2 指向同一个数据结构,引用计数器值为2 34 | str1 = str2; 35 | qDebug() << "str1 = " << str1; // str1 = "obmntu" 36 | qDebug() << "str2 = " << str2; // str2 = "obmntu" 37 | ``` 38 | 39 | 40 | 41 | QT中支持隐式共享的类还包括: 42 | 43 | - 所有的容器类 44 | - `QByteArray、 QBrush、QDir、 QBitmap、QPen、QImage、QCursor、QFont、QVariant`等 45 | 46 | 47 | 48 | 参见: 49 | 50 | [0016:Qt中的隐式共享](https://blog.csdn.net/newboy686/article/details/90183904) 51 | 52 | [Qt 中的隐式共享以及如何写一个隐式共享类](https://zhuanlan.zhihu.com/p/45354267) 53 | 54 | 55 | 56 | 57 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 58 | 59 | -------------------------------------------------------------------------------- /QT基础之默认main文件说明.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # Main.cpp 4 | 5 | 使用QT Creator 新建工程(基类选择 QDialog 为例)后会生成一个默认的main.cpp文件 6 | 7 | ```cpp 8 | #include "dialog.h" 9 | 10 | #include 11 | 12 | int main(int argc, char *argv[]) 13 | { 14 | QApplication a(argc, argv); 15 | Dialog w; 16 | w.show(); 17 | return a.exec(); 18 | } 19 | ``` 20 | 21 | 22 | 23 | **#include "dialog.h"** 24 | 25 | 包含程序中要完成功能的Dialog类的定义,在Dialog类中封装完成所需要的功能。 26 | 27 | **#include ** 28 | 29 | 每个使用QT图形化应用程序中都必须使用一个QApplication对象。QApplication管理各种各样的图形化应用程序的广泛资源、基本设置、控制流以及事件处理等。 30 | 31 | **int main(int argc, char *argv[])** 32 | 33 | 应用程序的如空,几乎在所有使用QT的情况下,main()函数只需要在将控制转交给QT库之前执行初始化,然后QT库通过事件向程序告知用户的行为。所有QT程序中都必须有且只有一个main()函数。`argc` 命令行变量的数量,` *argv[]` 命令行变量的数组。 34 | 35 | **QApplication a(argc, argv)** 36 | 37 | a是 程序的 QApplication 对象。QApplication 对象必须在任何QT窗口系统部件被使用之前创建。 38 | 39 | **w.show();** 40 | 41 | 创建的窗口部件必须调用show()函数使其可见,默认它是不可见的。 42 | 43 | **return a.exec();** 44 | 45 | 程序进入消息循环,等待可能的输入进行响应。main()函数在此将控制权转交给QT。在 exec() 中QT接收并处理用户和系统的事件并且将它们传递给适当的窗口部件。 46 | 47 | 48 | 49 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 50 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [TOC] 2 | 3 | # QT 4 | 5 | QT基础与实例应用,基于书籍 QT5开发及实例 第4版 6 | 7 | 环境 Win10 Qt5.12.10 8 | 9 | 更多参见 10 | [QT基础与实例应用目录](https://blog.csdn.net/leacock1991/article/details/118662440) 11 | 12 | 13 | | QT基础篇 | 14 | | :--| 15 | | [QT基础之QT5.12下载与安装](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BQT5.12%E4%B8%8B%E8%BD%BD%E4%B8%8E%E5%AE%89%E8%A3%85.md) | 16 | | [QT基础之默认main文件说明](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E9%BB%98%E8%AE%A4main%E6%96%87%E4%BB%B6%E8%AF%B4%E6%98%8E.md0) | 17 | | [QT基础之信号与槽机制](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E4%BF%A1%E5%8F%B7%E4%B8%8E%E6%A7%BD%E6%9C%BA%E5%88%B6.md)| 18 | | [QT基础之字符串类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB.md)| 19 | | [QT基础之容器类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%AE%B9%E5%99%A8%E7%B1%BB.md)| 20 | | [QT基础之QVariant类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BQVariant%E7%B1%BB.md)| 21 | |[QT基础之常用控件简单介绍](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%B8%B8%E7%94%A8%E6%8E%A7%E4%BB%B6%E7%AE%80%E5%8D%95%E4%BB%8B%E7%BB%8D.md)| 22 | |[QT基础之隐式共享](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E9%9A%90%E5%BC%8F%E5%85%B1%E4%BA%AB.md)| 23 | |布局管理| 24 | |[QT基础之分割窗口类QSplitter类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%88%86%E5%89%B2%E7%AA%97%E5%8F%A3QSplitter%E7%B1%BB.md) | 25 | |[QT基础之停靠窗口QDockWidget类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%81%9C%E9%9D%A0%E7%AA%97%E5%8F%A3QDockWidget%E7%B1%BB.md) | 26 | |[QT基础之堆栈窗体QStackedWidget类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%A0%86%E6%A0%88%E7%AA%97%E4%BD%93QStackedWidget%E7%B1%BB.md) | 27 | |[QT基础之基本布局QLayout](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%9F%BA%E6%9C%AC%E5%B8%83%E5%B1%80QLayout.md) | 28 | |[QT基础之QLayout综合实例](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BQLayout%E7%BB%BC%E5%90%88%E5%AE%9E%E4%BE%8B.md) | 29 | |基本对话框 | 30 | |[QT基础之基本对话框](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%9F%BA%E6%9C%AC%E5%AF%B9%E8%AF%9D%E6%A1%86.md) | 31 | |[QT基础之QToolBox工具盒类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BQToolBox%E5%B7%A5%E5%85%B7%E7%9B%92%E7%B1%BB.md) | 32 | |[QT基础之基础进度条](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%9F%BA%E7%A1%80%E8%BF%9B%E5%BA%A6%E6%9D%A1.md) | 33 | |[QT基础之QPalette类](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BQPalette%E7%B1%BB.md) | 34 | |[QT基础之QPalette实例电子时钟](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BQPalette%E5%AE%9E%E4%BE%8B%E7%94%B5%E5%AD%90%E6%97%B6%E9%92%9F.md) | 35 | |[QT基础之可扩展对话框](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%8F%AF%E6%89%A9%E5%B1%95%E5%AF%B9%E8%AF%9D%E6%A1%86.md) | 36 | |[QT基础之不规则窗体](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E4%B8%8D%E8%A7%84%E5%88%99%E7%AA%97%E4%BD%93.md) | 37 | |主窗口 | 38 | |[QT基础之主窗口构成](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E4%B8%BB%E7%AA%97%E5%8F%A3%E6%9E%84%E6%88%90.md) | 39 | |[QT基础之一文介绍文本编辑与排版包含字体相关设置、段落对齐与排序方式](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E4%B8%80%E6%96%87%E4%BB%8B%E7%BB%8D%E6%96%87%E6%9C%AC%E7%BC%96%E8%BE%91%E4%B8%8E%E6%8E%92%E7%89%88%E5%8C%85%E5%90%AB%E5%AD%97%E4%BD%93%E7%9B%B8%E5%85%B3%E8%AE%BE%E7%BD%AE%E3%80%81%E6%AE%B5%E8%90%BD%E5%AF%B9%E9%BD%90%E4%B8%8E%E6%8E%92%E5%BA%8F%E6%96%B9%E5%BC%8F.md) | 40 | |[QT基础之位置相关的函数介绍](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E4%BD%8D%E7%BD%AE%E7%9B%B8%E5%85%B3%E7%9A%84%E5%87%BD%E6%95%B0%E4%BB%8B%E7%BB%8D.md) | 41 | |图形绘制 | 42 | |[QT基础之一文介绍QPainter绘制基础图形](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E4%B8%80%E6%96%87%E4%BB%8B%E7%BB%8DQPainter%E7%BB%98%E5%88%B6%E5%9F%BA%E7%A1%80%E5%9B%BE%E5%BD%A2.md) | 43 | |[QT基础之双缓冲机制介绍](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8B%E5%8F%8C%E7%BC%93%E5%86%B2%E6%9C%BA%E5%88%B6%E4%BB%8B%E7%BB%8D.md) | 44 | |GraphicsView图形视图框架 | 45 | |[QT基础之GraphicsView图形视图框架介绍](https://github.com/lichangke/QT/blob/main/QT%E5%9F%BA%E7%A1%80%E4%B9%8BGraphicsView%E5%9B%BE%E5%BD%A2%E8%A7%86%E5%9B%BE%E6%A1%86%E6%9E%B6%E4%BB%8B%E7%BB%8D.md) | 46 | | | 47 | 48 | 希望我的文章对于大家有帮助,由于个人能力的局限性,文中可能存在一些问题,欢迎指正、补充! 49 | 50 | --------------------------------------------------------------------------------