在 Qt 4.4.3 菜单中执行单选按钮的方法

发布于 2024-08-14 14:26:49 字数 89 浏览 3 评论 0原文

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

有没有办法在 Qt v4.4.3 中轻松做到这一点?

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.

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

紙鸢 2024-08-21 14:26:49

我相信您会想要使用 QtActionGroup 对那些应该互斥的菜单项进行分组。它还使它们在渲染时看起来像单选按钮。是这样的:

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 类参考

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 menu items above should be groped together; more details here : QActionGroup Class Reference

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文