qradiobutton获取状态(pyqt qradiobutton)
radiobutton 怎么获取选中状态
用savedInstanceState,代码如下:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = (Button) findViewById(R.id.button);
RadioButton radiobutton1 = (RadioButton) findViewById(R.id.radiobutton1);
RadioButton radiobutton2 = (RadioButton) findViewById(R.id.radiobutton2);
if (savedInstanceState != null) {
boolean tmp1 = savedInstanceState.getBoolean("radio1");
if (tmp1) {
radiobutton1.setChecked(true);
}
boolean tmp2 = savedInstanceState.getBoolean("radio2");
if (tmp2) {
radiobutton2.setChecked(true);
}
}
if (IsRadioButton1Selected) {
radiobutton1.setChecked(true);
}
if (IsRadioButton2Selected) {
radiobutton2.setChecked(true);
}
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent it = new Intent(MainActivity.this, SecondActivity.class);
startActivity(it);
}
});
}
@Override
protected void onSaveInstanceState(Bundle outState) {
RadioButton radiobutton1 = (RadioButton) findViewById(R.id.radiobutton1);
RadioButton radiobutton2 = (RadioButton) findViewById(R.id.radiobutton2);
if (radiobutton1.isChecked()) {
IsRadioButton1Selected = true;
}
else if (radiobutton2.isChecked()) {
IsRadioButton2Selected = true;
}
else
Toast.makeText(this, "nothing selected", Toast.LENGTH_SHORT).show();
outState.putBoolean("radio1", IsRadioButton1Selected);
outState.putBoolean("radio2", IsRadioButton2Selected);
super.onSaveInstanceState(outState);
}
更多0
如何获取radiobutton是否选中
这样这个radio已经默认选中了
input type="radio" name="Sex" id="TIME" checked="checked" value="BYTIME"
使用这种方法可以获取当前的radio是否选中了,如果选中了就是true没选中就是false这是jquery的方法
$("#ISN").prop("checked")
获取value的值
$("#ISN").attr("value")如果这个不行就用$("#ISN").prop("value")
还有问题就问哥哥这段时间在做这方面的项目 懂得多 哈哈
判断QButtonGroup中哪个QRadioButton被选中
T qobject_cast ( QObject * object )如果object是T类型或者它的子类,就可以把object返回成T类型对象。否则返回0。类T必须是QObject的子类,而且必须声明宏:Q_OBJECTExample: Cpp代码 QObject *obj = new QTimer; // QTimer inherits QObject QTimer *timer = qobject_castQTimer *(obj); // timer == (QObject *)obj QAbstractButton *button = qobject_castQAbstractButton *(obj); // button == 0 问题 方法1、可以通过对象名称去判断Cpp代码 QAbstractButton *radioButton = qobject_castQAbstractButton * (ui.buttonGroup_1-checkedButton()); //ui.buttonGroup_1-checkedButton() 返回一个QRadioButton对象 //将它转换成QAbstractButton //,通过对象名称去判断 if(QString::compare(radioButton-objectName(), "topTubePositionRadio", Qt::CaseSensitive)) tubePosition = 0; else if(QString::compare(radioButton-objectName(), "bottomTubePositionRadio", Qt::CaseSensitive)) tubePosition = 1; else if (QString::compare(radioButton-objectName(), "lateralTubePositionRadio", Qt::CaseSensitive)) tubePosition = 2;
方法2:通过checkedId去判断首先需要在界面被激活初始化设置buttonGroup中的IdCpp代码 ui.buttonGroup_1-setId(ui.topTubePositionRadio,0);//topTubePositionRadio的Id设为0 ui.buttonGroup_1-setId(ui.bottomTubePositionRadio,1); ui.buttonGroup_1-setId(ui.lateralTubePositionRadio,2);
然后在你想获取哪个radioButton被选中时直接获取checkedId值,最后判断一下这个Id值就可以了。quint16 a = ui.buttonGroup_1-checkedId(); 很纳闷为啥QtDesigner中没有界面直接赋给这个radioButton,Id值?????或许是没有必要吧,第一种方法也可以。