Qt GUI中的单选按钮

Radio button in Qt GUI

本文关键字:单选按钮 GUI Qt      更新时间:2023-10-16

我使用Qt5.2.1,我做了一个程序来做一些事情。在它我添加了一个单选按钮(命名为"其他人"),我想,当用户点击这个按钮一行编辑弹出除了它,让用户输入一些东西里面。当用户单击另一个单选按钮时,此行编辑将消失。我该怎么做呢?

请帮帮我!

我希望当用户点击这个按钮(…)。我该怎么做呢?

QRadioButton

当一个按钮被打开或关闭时,它发出toggled() signal。连接到这个信号,如果你想触发一个动作当按钮改变状态时。使用isChecked()查看某个按钮是否被选中。

你也可以在QRadioButtons上写一个包装器,这样你就可以使用QSignalMapper将他们的toggled(bool)信号连接到这个包装器的单个插槽toggled(int)。然后,您可以在这样的包装器中管理所有这些逻辑:

void RadioHelper::initialize( const std::vector<
                                   QSharedPointer<RadioHelperEntry> >& entries)
{
    entries_ = entries;
    mapper_.reset(new QSignalMapper(this));
    EntriesIterator it = entries_.begin();
    int i = 0;
    while ( it!=entries_.end())
    {
       connect(( *it)->button_, SIGNAL( toggled(bool)), mapper_.data(), 
                                                                   SLOT(map()));
       mapper_->setMapping( ( *it)->button_, (int)( *it)->mode_);
       it++;
       i++;
    }
    connect( mapper_.data(), SIGNAL( mapped(int)), this, SIGNAL( toggled(int)));
    connect( this, SIGNAL( toggled(int)), this, SLOT( updateValue(int)));
}
void RadioHelper::updateValue( int v)
{
    value_ = v;
    emit valueChanged();
}

我找到我要找的东西了

界面-> radio_button -> setvisible(假);

^帮助我得到想要的结果