Loading

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中自定义的按键的位置。

posted @ 2022-09-03 19:46  师从名剑山  阅读(76)  评论(0编辑  收藏  举报