找回密码
 立即注册
收起左侧

多个按钮如何循环触发

3
回复
9819
查看
[复制链接]
累计签到:22 天
连续签到:1 天
来源: 2017-1-11 11:54:03 显示全部楼层 |阅读模式
1Qter豆
请教各位,如果界面中有多个按钮,现在要实现多个按钮循环触发的效果,比如每个按钮代表一种输出,让各种输出循环出现,应该怎么实现呢?

回复

使用道具 举报

累计签到:595 天
连续签到:1 天
2017-1-13 08:45:02 显示全部楼层
T QObject::findChild(const QString &name = QString(), Qt::FindChildOptions options = Qt::FindChildrenRecursively) const
Returns the child of this object that can be cast into type T and that is called name, or 0 if there is no such object. Omitting the name argument causes all object names to be matched. The search is performed recursively, unless options specifies the option FindDirectChildrenOnly.
If there is more than one child matching the search, the most direct ancestor is returned. If there are several direct ancestors, it is undefined which one will be returned. In that case, findChildren() should be used.
This example returns a child QPushButton of parentWidget named "button1", even if the button isn't a direct child of the parent:

  QPushButton *button = parentWidget->findChild<QPushButton *>("button1");

你可以把button命名为button1,button2...buttonx,就可以用上面的方法来实际循环调用了
回复

使用道具 举报

累计签到:8 天
连续签到:1 天
2017-1-12 10:34:32 显示全部楼层
本帖最后由 1363386323 于 2017-1-12 10:37 编辑

void button01Clicked()
{
   qDebug()<<"button01Clicked()";
    button02->clicked();
}

void button02Clicked()
{
   qDebug()<<"button02Clicked()";
    button03->clicked();
}

void button03Clicked()
{
   qDebug()<<"button03Clicked()";
    button01->clicked();
}

connect(button01,SIGNAL(clicked()),this,SLOT(button01Clicked()));
connect(button02,SIGNAL(clicked()),this,SLOT(button02Clicked()));
connect(button03,SIGNAL(clicked()),this,SLOT(button03Clicked()));


好了,就这样吧!
回复

使用道具 举报

累计签到:597 天
连续签到:1 天
2017-1-11 13:15:59 显示全部楼层
使用QTimer定时器可以定时间隔时间
然后使用QPushButton继承的槽函数animateClick()在定时器中实现触发
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

公告
可以关注我们的微信公众号yafeilinux_friends获取最新动态,或者加入QQ会员群进行交流:190741849、186601429(已满) 我知道了