你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

【经验分享】stm32基于TouchGFX的GUI开发(三):radioButton 控件的使用

[复制链接]
STMCU小助手 发布时间:2022-3-9 11:17
一、创建控件
1、创建4个radioButton,和两个text Area控件。

8V7QD}5(L43LKK~0R_IS{]V.png

  1. radioButton1 Loacation: X:56 Y: 25
  2. radioButton2 Loacation: X:56 Y: 78
  3. radioButton3 Loacation: X:56 Y: 129
  4. radioButton4 Loacation: X:56 Y: 179
  5. selectedText Loacation:    X:114 Y: 137
  6. deselectedTextLoacation: X:114 Y: 189
  7. 同时分别设置四个radioButton的背景图片如下所示:
  8. radioButton可以在SELECTION栏里设置默认启动时是否选择此radioButton。
复制代码

0XB(CDEC[(N8)PNIYBJJ8YF.png

然后按照下图给Text Area添加文本资源

{)~02V@S3PRKN{H`KSN{L`6.png

二、实现交互
一共添加8个InterAction,每个radioButton添加一个selected和deselected的InterAction。

EV`P4A}DTZNEY`QA5T60[E0.png
DWRJN@ZU(LBEH)`W2SMN`HN.png

依次向8个interactions的code里面添加如下C++代码

  1. //radioButton1的selected时执行的C++代码
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 1);
  3. selectedText.resizeToCurrentText();
  4. selectedText.invalidate();
复制代码
  1. //radioButton2的selected时执行的C++代码
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 2);
  3. selectedText.resizeToCurrentText();
  4. selectedText.invalidate();
复制代码
  1. //radioButton3的selected时执行的C++代码
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 3);
  3. selectedText.resizeToCurrentText();
  4. selectedText.invalidate();
复制代码
  1. //radioButton4的selected时执行的C++代码
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 4);
  3. selectedText.resizeToCurrentText();
  4. selectedText.invalidate();
复制代码
  1. //radioButton1的deselected时执行的C++代码
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 1);
  3. deselectedText.resizeToCurrentText();
  4. deselectedText.invalidate();
复制代码
  1. //radioButton2的deselected时执行的C++代码
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 2);
  3. deselectedText.resizeToCurrentText();
  4. deselectedText.invalidate();
复制代码
  1. //radioButton3的deselected时执行的C++代码
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 3);
  3. deselectedText.resizeToCurrentText();
  4. deselectedText.invalidate();
复制代码
  1. //radioButton4的deselected时执行的C++代码
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 4);
  3. deselectedText.resizeToCurrentText();
  4. deselectedText.invalidate();
复制代码

Runsimulation即可看到最终演示结果和我们预期相同。




收藏 评论0 发布时间:2022-3-9 11:17

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版