当前位置:网站首页>[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

边栏推荐
- 2022 cable crane driver examination registration and cable crane driver certificate examination
- JDBC courses
- Test shift right: Elk practice of online quality monitoring
- leetcode 2097 — 合法重新排列数对
- 【FH-GFSK】FH-GFSK信号分析与盲解调研究
- 按键精灵打怪学习-前台和内网发送后台验证码
- [interview question] 1369 when can't I use arrow function?
- C application interface development foundation - form control (2) - MDI form
- 测试右移:线上质量监控 ELK 实战
- After reading this article, I will teach you to play with the penetration test target vulnhub - drivetingblues-9
猜你喜欢

MySQL foundation 05 DML language

音程的知识的总结

Give you an array numbers that may have duplicate element values. It was originally an array arranged in ascending order, and it was rotated once according to the above situation. Please return the sm
![[技术发展-23]:DSP在未来融合网络中的应用](/img/2e/f39543a18a8f58b1d341ce72cc4427.png)
[技术发展-23]:DSP在未来融合网络中的应用

Basic remote connection tool xshell

CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr

Database SQL language 01 where condition

C#应用程序界面开发基础——窗体控制(1)——Form窗体

Steps to obtain SSL certificate private key private key file

Androd Gradle 对其使用模块依赖的替换
随机推荐
数学知识:能被整除的数—容斥原理
LeetCode 987. Vertical order transverse of a binary tree - Binary Tree Series Question 7
Androd Gradle 对其使用模块依赖的替换
Androd gradle's substitution of its use module dependency
[day 29] given an integer, please find its factor number
Machine learning terminology
Vim 9.0正式发布!新版脚本执行速度最高提升100倍
按键精灵打怪学习-多线程后台坐标识别
并发编程的三大核心问题 -《深入理解高并发编程》
如今少年已归来,人间烟火气最抚凡人心 复工了~
Detailed explanation of Q-learning examples of reinforcement learning
Thinkphp+redis realizes simple lottery
按鍵精靈打怪學習-多線程後臺坐標識別
测试右移:线上质量监控 ELK 实战
按键精灵打怪学习-自动回城路线的判断
C#应用程序界面开发基础——窗体控制(1)——Form窗体
What is tone. Diao's story
SwiftUI 组件大全之使用 SceneKit 和 SwiftUI 构建交互式 3D 饼图(教程含源码)
按键精灵打怪学习-自动寻路回打怪点
Test shift right: Elk practice of online quality monitoring