QDialogButtonBox用法

QDialogButtonBox

1、申明BOX按键

setStandardButtons(QDialogButtonBox::Reset|QDialogButtonBox::Cancel|QDialogButtonBox::Ok)
其值可以如下:
 enum StandardButton {
        // keep this in sync with QMessageBox::StandardButton and QPlatformDialogHelper::StandardButton
        NoButton           = 0x00000000,
        Ok                 = 0x00000400,
        Save               = 0x00000800,
        SaveAll            = 0x00001000,
        Open               = 0x00002000,
        Yes                = 0x00004000,
        YesToAll           = 0x00008000,
        No                 = 0x00010000,
        NoToAll            = 0x00020000,
        Abort              = 0x00040000,
        Retry              = 0x00080000,
        Ignore             = 0x00100000,
        Close              = 0x00200000,
        Cancel             = 0x00400000,
        Discard            = 0x00800000,
        Help               = 0x01000000,
        Apply              = 0x02000000,
        Reset              = 0x04000000,

2、设置样式:

  QDialogButtonBox > QPushButton { color: white; } //box中的按钮文字改为白色

3、处理按键集消息

函数消息: clicked(QPushButton* button);

再此消息中  使用 buttonBox->button(QDialogButtonBox::Ok) == button //判定是点击勒那个按钮,此处判定是不是点击了确定按钮

4、处理个别消息

connect(ui->buttonBox->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), this, SLOT(slotButtonCancel()));
 connect(ui->buttonBox->button(QDialogButtonBox::Apply), SIGNAL(clicked()), this, SLOT(slotButtonOk()));

5、构造函数连接:

connect(ui->buttonBox, SIGNAL(accepted()), this, SLOT(slotButtonA()));
connect(ui->buttonBox, SIGNAL(rejected()), this, SLOT(slotButtonB()));
以上Cancel按钮能成功响应slotButtonB(),Apply按钮无响应

6、语言切换

QDialogButtonBox: 会自动翻译成当前系统语言,会自动根据是windows 或 mac 来改变按钮顺序

 

如果希望它显示和你的程序相同的语言则要:

QDialogButtonBox->button(QDialogButtonBox::Ok)->setText(tr("Ok"));

也就是给你所用的按钮重新设置名字,然后翻译就可

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值