QDialogButtonBox使用方法总结

第一此使用QDialogButtonBox按钮盒子,这个按钮盒子可以用系统自带的默认按钮,也可以自己定制按钮使用。

#include <QDialogButtonBox> //包含头文件
button_Box = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel);//设置两个按钮
Constant                Value       Description
QDialogButtonBox::Ok        0x00000400  An "OK" button defined with the AcceptRole.
QDialogButtonBox::Open      0x00002000  A "Open" button defined with the AcceptRole.
QDialogButtonBox::Save      0x00000800  A "Save" button defined with the AcceptRole.
QDialogButtonBox::Cancel    0x00400000  A "Cancel" button defined with the RejectRole.
QDialogButtonBox::Close     0x00200000  A "Close" button defined with the RejectRole.
QDialogButtonBox::Discard   0x00800000  A "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole.
QDialogButtonBox::Apply     0x02000000  An "Apply" button defined with the ApplyRole.
QDialogButtonBox::Reset     0x04000000  A "Reset" button defined with the ResetRole.
QDialogButtonBox::RestoreDefaults   0x08000000  A "Restore Defaults" button defined with the ResetRole.
QDialogButtonBox::Help      0x01000000  A "Help" button defined with the HelpRole.
QDialogButtonBox::SaveAll   0x00001000  A "Save All" button defined with the AcceptRole.
QDialogButtonBox::Yes       0x00004000  A "Yes" button defined with the YesRole.
QDialogButtonBox::YesToAll  0x00008000  A "Yes to All" button defined with the YesRole.
QDialogButtonBox::No        0x00010000  A "No" button defined with the NoRole.
QDialogButtonBox::NoToAll   0x00020000  A "No to All" button defined with the NoRole.
QDialogButtonBox::Abort     0x00040000  An "Abort" button defined with the RejectRole.
QDialogButtonBox::Retry     0x00080000  A "Retry" button defined with the AcceptRole.
QDialogButtonBox::Ignore    0x00100000  An "Ignore" button defined with the AcceptRole.
QDialogButtonBox::NoButton  0x00000000  An invalid button.
button_Box = new QDialogButtonBox(QDialogButtonBox::Ok
                                      | QDialogButtonBox::Cancel
                                      | QDialogButtonBox::Open
                                      | QDialogButtonBox::Save
                                      | QDialogButtonBox::Close
                                      | QDialogButtonBox::Discard
                                      | QDialogButtonBox::Apply
                                      | QDialogButtonBox::Reset
                                      | QDialogButtonBox::RestoreDefaults
                                      | QDialogButtonBox::Help
                                      | QDialogButtonBox::SaveAll);

对于上面按钮盒子里面的按钮,可以供选择和使用的哦这些
规则有下面的规则:
accepted Role(同意规则),rejected Role,ApplayRole,HelpRole,ResetRole,YesRole
按钮盒里面部分按钮

第二种使用方法,在按钮盒子中添加自己想要的按钮

    QDialogButtonBox* button_Box2 = new  QDialogButtonBox(Qt::Vertical);  //Qt::Horizontal
    QPushButton* button_add = new QPushButton(tr("&Add"));
    QPushButton* button_divid = new QPushButton(tr("&Divid"));
    QPushButton* button_multiply = new QPushButton(tr("&Multiply"));
    QPushButton* button_subtract = new QPushButton(tr("&Subtract"));

    button_Box2->addButton(button_add,QDialogButtonBox::ActionRole);
    button_Box2->addButton(button_divid,QDialogButtonBox::ActionRole);
    button_Box2->addButton(button_multiply,QDialogButtonBox::ActionRole);
    button_Box2->addButton(button_subtract,QDialogButtonBox::ActionRole);
    mainlayout->addWidget(button_Box2);

    this->setLayout(mainlayout);

QDialogButtonBox使用方法总结_第1张图片

这里写图片描述

你可能感兴趣的:(Qt)