当前位置: 代码迷 >> QT开发 >> 怎么改变按钮的显示文字
  详细解决方案

怎么改变按钮的显示文字

热度:114   发布时间:2016-04-25 04:58:50.0
如何改变按钮的显示文字
现做一个可以改变形状的对话框。当开始时显示More>>>单击后变成More<<<再单击变成More>>>,以此循环。
想到一个方法是加一个槽void seText();
connect(moreButton, SIGNAL(clicked()), this, SLOT(seText()));
其中槽为:
void seText(){
if (moreButton->text()=="&More>>>")
  moreButton->setText("&More<<<");
else
  moreButton->setText("&More>>>");
}
不知道这样的方法可行不?总感觉这个字符串匹配有点问题,不知道有没有更好的方法?

------解决方案--------------------
用一个静态的static布尔变量来判断
------解决方案--------------------
打印moreButton->text(),看看到底是什么

另外可以判断字符串中是否包含'<' 或者 '>'

再另外用一个bool类成员变量

最后2楼方法

void seText(){
static bool flag = false;
if (flag == false)
moreButton->setText("&More<<<");
else
moreButton->setText("&More>>>");
flag = !flag;
}
  相关解决方案