如何使用QT4单选按钮?
我做了简单的 Qt4 设计,我想让它与 c++ 一起工作,但我在使用 QT4 单选按钮时遇到了问题。我有文本字段、两个单选按钮和一个提交按钮。我想在单击提交按钮时检查选中了哪个单选按钮以及文本字段中的信息是什么。我正在获取文本字段信息,但我找不到如何检查哪个单选按钮被选中(如果有的话)。
I've made simple Qt4 design and I want to make it work with c++ but I've got problem with QT4 radio buttons. I have text field, two radio buttons and a submit button. I want when the submit button is clicked to check which radio button is checked and what is the information in the text field. I'm getting the text field info but I can't find how to check which radio button is check if any is checked.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
单选按钮在单选按钮组中是互斥的。默认情况下,如果单选按钮具有相同的父级,则它们属于同一组。
确保在启动时检查单选按钮之一,方法是在 UI 设计器中检查单选按钮或在代码中启动时检查。
单击提交按钮后,通过调用
radioButtonName.isChecked()
检查每个单选按钮。查看 Qt 文档时,不要忘记查看类的整个继承层次结构的文档。
isChecked()
函数记录在QAbstractButton
类中,因为此状态对于许多不同的按钮子类都有效:)Radio buttons are mutually exclusive within a radio button group. By default, radio buttons are part of the same group if they have the same parent.
Make sure one of your radio buttons is checked at start up either by checking one in your UI designer or at start up in code.
When your submit button is clicked, check each radio button by calling
radioButtonName.isChecked()
.When looking at Qt documentation, don't forget to look at the documentation for the entire inheritance hierarchy for a class. The
isChecked()
function is documented way up in theQAbstractButton
class as this state is valid for many different button sub classes :)