Qt 4.4.3菜单中的单选按钮的制作方法 [英] Way to do radio buttons in Qt 4.4.3 menus

查看:356
本文介绍了Qt 4.4.3菜单中的单选按钮的制作方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Linux上,希望有一组互斥的菜单项,并且通过单选按钮而不是复选框来指定当前选择的菜单项.

On Linux would like to have a set of menu items which are mutually exclusive and have the currently selected one be designated by a radio button instead of a checkbox.

在Qt v4.4.3中是否可以轻松地做到这一点?

Is there a way to do this in Qt v4.4.3 easily?

推荐答案

我相信您希望使用QtActionGroup对那些应该互斥的菜单项进行分组.这也使它们在渲染时看起来像单选按钮.像这样:

I believe you would want to use QtActionGroup to group those menu items which should be mutually exclusive. It also makes them look like a radio button when rendered. Smth like this:

QActionGroup* group = new QActionGroup( this );

ui->actionTest1->setCheckable(true);
ui->actionTest2->setCheckable(true);
ui->actionTest3->setCheckable(true);

ui->actionTest1->setActionGroup(group);
ui->actionTest2->setActionGroup(group);
ui->actionTest3->setActionGroup(group);

上面的3个菜单项应放在一起;此处有更多详细信息: QActionGroup类参考

3 menu items above should be groped together; more details here : QActionGroup Class Reference

这篇关于Qt 4.4.3菜单中的单选按钮的制作方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆