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

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

[复制链接]
STMCU小助手 发布时间:2022-3-9 11:17
一、创建控件
" M6 |. o1 p4 g/ R# E/ P1 P) ]1、创建4个radioButton,和两个text Area控件。6 A2 C5 d1 a7 l0 j
  q! J3 Y  ?0 z3 x
8V7QD}5(L43LKK~0R_IS{]V.png 2 w) I& W1 d8 E. Q1 ]1 @

! ]/ y& X4 A2 L0 R
  1. radioButton1 Loacation: X:56 Y: 25  Q3 P, a, _" J" }2 r$ E
  2. radioButton2 Loacation: X:56 Y: 78
    6 L7 D5 g0 P6 ?3 c
  3. radioButton3 Loacation: X:56 Y: 129, M$ n* H! P, J' ^
  4. radioButton4 Loacation: X:56 Y: 179& z$ e! u9 Z# v& P% b* d4 [
  5. selectedText Loacation:    X:114 Y: 137* Y: [" R5 I6 s8 Q
  6. deselectedTextLoacation: X:114 Y: 189
    4 X) M/ v9 c- e) C+ A
  7. 同时分别设置四个radioButton的背景图片如下所示:" o/ h5 K( J- Y# M$ ?
  8. radioButton可以在SELECTION栏里设置默认启动时是否选择此radioButton。
复制代码
6 U0 n1 f# Z: l3 G1 S' m
0XB(CDEC[(N8)PNIYBJJ8YF.png ; O. b6 u/ C; C3 ?; U& K9 h
3 n: r4 {' Y6 F$ D4 b7 Z
然后按照下图给Text Area添加文本资源$ F2 w7 n5 y4 j" ]" f6 p- Z

. h7 v: Q: j/ ^ {)~02V@S3PRKN{H`KSN{L`6.png - O! q+ [& R  R/ m/ S" D

1 x% O* A( n! b& k2 }二、实现交互5 C& k. w3 Q  E+ e/ F* w0 j
一共添加8个InterAction,每个radioButton添加一个selected和deselected的InterAction。
% H( J2 k5 K0 U" V. i8 U2 t7 w7 u) V0 ~# ?; _& V
EV`P4A}DTZNEY`QA5T60[E0.png & u: F! ^$ M* l. t# Y6 m5 ~. P: L
DWRJN@ZU(LBEH)`W2SMN`HN.png
; A* }& W3 J2 h; w/ I/ K# _% r
* z3 |/ X0 G9 ], V6 B0 w依次向8个interactions的code里面添加如下C++代码% ~; [, L- Q8 a/ Z8 N$ n* B
5 y# B$ A+ K9 q% ?# k
  1. //radioButton1的selected时执行的C++代码$ z$ o& Q3 ~2 O$ g5 M( I7 X
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 1);* @, t3 D- g4 E) ]
  3. selectedText.resizeToCurrentText();
    / q- ]/ r+ V6 d: f+ J
  4. selectedText.invalidate();
复制代码
  1. //radioButton2的selected时执行的C++代码! W' ?, v7 E* f: I3 e( {1 N  \
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 2);5 T. e4 k8 i% i- G
  3. selectedText.resizeToCurrentText();
    # @( c7 y$ k$ P: {! e5 t- [
  4. selectedText.invalidate();
复制代码
  1. //radioButton3的selected时执行的C++代码6 i/ p. C, v% U% ]
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 3);
    9 I) \! \" @5 {7 e+ E, v
  3. selectedText.resizeToCurrentText();1 j  h/ e5 N- \! s5 [6 V+ c9 J; v
  4. selectedText.invalidate();
复制代码
  1. //radioButton4的selected时执行的C++代码- L# B; l& p) y/ b/ K: ~
  2. Unicode::snprintf(selectedTextBuffer, 4, "%d", 4);
    1 y6 Z* n0 G5 j* u; a0 c
  3. selectedText.resizeToCurrentText();. o0 j+ [! e" v  I5 j* }$ I
  4. selectedText.invalidate();
复制代码
  1. //radioButton1的deselected时执行的C++代码0 C- D! N2 M& c3 B# o
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 1);
    4 V& [0 I! x; u: w. X
  3. deselectedText.resizeToCurrentText();
    / t$ A" S% P' h1 O- q0 |2 h
  4. deselectedText.invalidate();
复制代码
  1. //radioButton2的deselected时执行的C++代码9 ^  d, A; P1 _% E' i$ P
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 2);
    & E* q7 ?9 s: y" k
  3. deselectedText.resizeToCurrentText();1 c: p  C1 _! r
  4. deselectedText.invalidate();
复制代码
  1. //radioButton3的deselected时执行的C++代码
    ! k: W( S  G. S1 J4 r5 k
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 3);
    0 G" [& Z) ~- Z! m
  3. deselectedText.resizeToCurrentText();9 D( t4 D/ }6 U. p4 u
  4. deselectedText.invalidate();
复制代码
  1. //radioButton4的deselected时执行的C++代码
    / G$ p4 {- m! @. D8 V8 d
  2. Unicode::snprintf(deselectedTextBuffer, 4, "%d", 4);, m2 y& E- w. b& e) V5 l) G/ ~
  3. deselectedText.resizeToCurrentText();# T0 W/ B. r$ |& }7 F
  4. deselectedText.invalidate();
复制代码

& d1 ]: g& ^$ x* e& H  XRunsimulation即可看到最终演示结果和我们预期相同。
9 N0 |! y# e) [( x5 N# b$ \. r2 D: s
9 C6 L* Y" n: S! o
7 Q& w9 F; _$ q- r8 d: r
! f" |/ h4 l6 V) V
赞 收藏 评论0 发布时间:2022-3-9 11:17

举报

0个回答

所属标签

相似技术帖

官网相关资源

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
人形机器人运动控制、感知与智能配电
半导体创新技术与应用方向
EE架构与软件定义汽车
12V/48V 汽车智能配电(SPD)
区域控制单元(ZCU)与分区架构
关注我们
st-img 微信公众号
st-img 手机版