当前位置:网站首页>[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
边栏推荐
- wirehark数据分析与取证A.pacapng
- 数学知识:台阶-Nim游戏—博弈论
- Create your first Kivy program Hello word (tutorial includes source code)
- Test shift right: Elk practice of online quality monitoring
- How is the mask effect achieved in the LPL ban/pick selection stage?
- 【数据挖掘】任务5:K-means/DBSCAN聚类:双层正方形
- 并发编程的三大核心问题 -《深入理解高并发编程》
- 强化学习 Q-learning 实例详解
- Key wizard hit strange learning - automatic path finding back to hit strange points
- 英语常用词汇
猜你喜欢
leetcode刷题_两数之和 II - 输入有序数组
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
[C language] detailed explanation of pointer and array written test questions
【QT】自定义控件的封装
【面试题】1369- 什么时候不能使用箭头函数?
【C语言】指针与数组笔试题详解
CF1617B Madoka and the Elegant Gift、CF1654C Alice and the Cake、 CF1696C Fishingprince Plays With Arr
Meituan dynamic thread pool practice ideas, open source
C#应用程序界面开发基础——窗体控制(3)——文件类控件
简易分析fgui依赖关系工具
随机推荐
音程的知识的总结
Is there anything in common between spot gold and spot silver
传输层 TCP主要特点和TCP连接
Look at how clothing enterprises take advantage of the epidemic
Niu Ke swipes questions and clocks in
电信客户流失预测挑战赛
数学知识:Nim游戏—博弈论
C application interface development foundation - form control (2) - MDI form
openresty 缓存
看完这篇 教你玩转渗透测试靶机Vulnhub——DriftingBlues-9
【FH-GFSK】FH-GFSK信号分析与盲解调研究
Basic remote connection tool xshell
[Cao gongzatan] after working in goose factory for a year in 2021, some of my insights
Machine learning terminology
[C language] detailed explanation of pointer and array written test questions
[Arduino experiment 17 L298N motor drive module]
JDBC courses
Mathematical knowledge: divisible number inclusion exclusion principle
串口抓包/截断工具的安装及使用详解
Wireshark data analysis and forensics a.pacapng