I would like to have a QDialogButtonBox
with three buttons in this particular order:
Ok | Apply | Cancel
Is it possible to reorder the buttons to put Apply
in the center?
The button layout is platform specific.
Windows - Ok | Cancel | Apply
OS X - Apply | Cancel | Ok
KDE - Ok | Apply | Cancel
GNOME - Apply | Cancel | Ok
There is two way to force use non standard layout.
You can subclass QProxyStyle
and reimplement styleHint method, to provide custom style for QStyle::SH_DialogButtonLayout
styleHint.
class KdeStyle : public QProxyStyle
{
public:
virtual int styleHint(StyleHint stylehint, const QStyleOption *opt, const QWidget *widget, QStyleHintReturn *returnData) const override
{
if (stylehint == SH_DialogButtonLayout)
return QDialogButtonBox::KdeLayout;
return QProxyStyle::styleHint(stylehint, opt, widget, returnData);
}
};
Then apply custom style to application.
qApp->setStyle(new KdeStyle());
Another way to do it, is using stylesheets. button-layout property specify the layout of buttons in a QDialogButtonBox
or a QMessageBox
. The possible values are 0 (WinLayout
), 1 (MacLayout
), 2 (KdeLayout
), and 3 (GnomeLayout
).
QDialogButtonBox *buttonBox = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Apply | QDialogButtonBox::Cancel);
buttonBox->setStyleSheet("* { button-layout: 2 }");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With