找回密码
 立即注册

多个按钮如何循环触发

发表于 2017-1-11 11:54:03 | 显示全部楼层 |阅读模式
1Qter豆
请教各位,如果界面中有多个按钮,现在要实现多个按钮循环触发的效果,比如每个按钮代表一种输出,让各种输出循环出现,应该怎么实现呢?

回复

使用道具 举报

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

使用道具 举报

发表于 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()));


好了,就这样吧!
回复

使用道具 举报

发表于 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,就可以用上面的方法来实际循环调用了
回复

使用道具 举报

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

本版积分规则

lanyueliang805

    主题

    帖子

    47

    积分

    Qter1级会员

    Rank: 1

    积分
    47

Qter1级会员

发私信

Qt开源社区——开源 共享 自由

微信扫一扫
查看精品教程!