当前位置:网站首页>[QT] encapsulation of custom controls
[QT] encapsulation of custom controls
2022-07-03 01:33:00 【StudyWinter】
Yes QT Custom control encapsulation .
1 Create a project , choice UI Interface , Inherit Widget class .
2 Create designer interface class , Right click on the item



Take the class name yourself , When it's done . Finally, it will generate ,h/.cpp/.ui file
3 Click the generated UI file

Drag the required controls . Use here Horizontal Slider and Spin Box.
The final effect is to drag Horizontal Slider,Spin Box The number of will change ; modify Spin Box The number of ,Horizontal Slider It will slide .

You can also modify initialization , The two should correspond

4 stay ui Add in the interface widget Control , Promote it to the designer interface class created before

5 Create designer interface class ( Name self access )

6 Use signal slots to complete requirements ;
6.1 The first set 【spinBox The numbers change , yes slider Slide with 】
see QSpinBox, It has an overloaded version , Use function pointers to complete ,

// spinBox The numbers change , yes slider Slide with
// A function pointer
void(QSpinBox::* spin)(int) = &QSpinBox::valueChanged;
connect(ui->spinBox, spin, ui->horizontalSlider,&QSlider::setValue);
next , Empathy
// slider Move ,spinBox The numbers change
connect(ui->horizontalSlider, &QSlider::valueChanged, ui->spinBox, &QSpinBox::setValue);6.2 stay widget.ui Add two buttons ,【 Set to half 】 and 【 Set to half 】

stay Smallwidget Add two functions to the class 【 Set up the data 】 and 【 get data 】

Realization

stay Widget.cpp To realize the signal and slot of the button
// Click Set half
connect(ui->btn_set, &QPushButton::clicked, this, [=](){
ui->widget->setVal(50);
});
// Click to get the current value
connect(ui->btn_get, &QPushButton::clicked, this, [=](){
qDebug() << ui->widget->getVal();
});
effect

边栏推荐
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- 看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
- What operations need attention in the spot gold investment market?
- Tp6 fast installation uses mongodb to add, delete, modify and check
- GDB 在嵌入式中的相关概念
- After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
- Is there anything in common between spot gold and spot silver
- Concise analysis of redis source code 11 - Main IO threads and redis 6.0 multi IO threads
- 【C语言】指针与数组笔试题详解
- leetcode 6103 — 从树中删除边的最小分数
猜你喜欢

MySQL foundation 04 MySQL architecture

Basic concept and implementation of overcoming hash

leetcode刷题_两数之和 II - 输入有序数组

What is tone. Diao's story

简易分析fgui依赖关系工具

C application interface development foundation - form control (2) - MDI form

C#应用程序界面开发基础——窗体控制(1)——Form窗体
![[技术发展-23]:DSP在未来融合网络中的应用](/img/2e/f39543a18a8f58b1d341ce72cc4427.png)
[技术发展-23]:DSP在未来融合网络中的应用

C#应用程序界面开发基础——窗体控制(3)——文件类控件

leetcode 6103 — 从树中删除边的最小分数
随机推荐
【C语言】指针与数组笔试题详解
并发编程的三大核心问题 -《深入理解高并发编程》
Button wizard play strange learning - automatic return to the city route judgment
数学知识:台阶-Nim游戏—博弈论
The meaning of wildcard, patsubst and notdir in makefile
C application interface development foundation - form control (3) - file control
[C language] detailed explanation of pointer and array written test questions
Test shift right: Elk practice of online quality monitoring
MySQL foundation 06 DDL
[flutter] icons component (fluttericon Download Icon | customize SVG icon to generate TTF font file | use the downloaded TTF icon file)
Mathematical Knowledge: Steps - Nim Games - Game Theory
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
按键精灵打怪学习-自动回城路线的判断
Top ten regular spot trading platforms 2022
Kivy tutorial how to create drop-down lists in Kivy
Database SQL language 02 connection query
The latest analysis of tool fitter (technician) in 2022 and the test questions and analysis of tool fitter (technician)
Pytest learning notes (12) -allure feature · @allure Step () and allure attach
dotConnect for PostgreSQL数据提供程序
Now that the teenager has returned, the world's fireworks are the most soothing and ordinary people return to work~