Qt ButtonRole参数的作用

QMessgageBox中addButton(QAbstructButton* , ButtonRole),ButtonRole的作用

最近在用QMessageBox,发现addButton这个函数有一个参数,ButtonRole,在官方文档里的定义是这个:
在这里插入图片描述
This enum describes the roles that can be used to describe buttons in the button box. Combinations of these roles are as flags used to describe different aspects of their behavior.

此枚举描述可用于描述按钮框中的按钮的角色。 这些角色的组合作为标志,用于描述其行为的不同方面。

但是看这个介绍好像有点不明所以,直到,我去Qt Forum发帖问一下,我得到了可能是正确的答案。
在这里插入图片描述

然后我写了下面的代码:

QMessageBox* box = new QMessageBox(this);
QPushButton* button1 = new QPushButton("是",this);
box->addButton(button1, QMessageBox::NoRole);

QPushButton* button = new QPushButton("否",this);
box->addButton(button, QMessageBox::YesRole);
box->show();

然后我得到了如下结果:
请添加图片描述
所以我认为ButtonRole的作用是,让系统根据你设置的ButtonRole来安排你的QMessageBox中自定义的按键的位置。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值