菜单中做单选按钮的方法

菜单中做单选按钮的方法

本文介绍了在 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 菜单中做单选按钮的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 04:06