Widget::Widget(QWidget *parent) :
QWidget(parent),
ui(new Ui::Widget)
{
ui->setupUi(this);
QButtonGroup *m_buGroup = new QButtonGroup(this);//按钮组
ui->pushButton1->setFocusPolicy(Qt::NoFocus);//设置按钮无焦点
ui->pushButton2->setFocusPolicy(Qt::NoFocus);//设置按钮无焦点
m_buGroup->addButton(ui->pushButton1,1);//添加按钮到
m_buGroup->addButton(ui->pushButton2,3);//添加按钮到
QObject::connect(m_buGroup, SIGNAL(buttonClicked(int)),this, SLOT(buttonNumslot(int)));
}
void Widget::buttonNumslot(int bn){if(ui->lineEdit->hasFocus())//输入框1焦点{
ui->lineEdit->insert(QString::number(bn));}
else if(ui->lineEdit_2->hasFocus())//输入框2焦点{
ui->lineEdit_2->insert(QString::number(bn));}
}按下pushButton1输入1,按下pushButton2输入3,改选lineEdit_2后则输入到lineEdit中