[Qgis-developer] Qt 4.2 QDialogButtonBox and
QMessageBox::StandardButton
Tom Elwertowski
telwertowski at comcast.net
Thu Jan 18 04:04:08 EST 2007
Hi all,
Qt 4.2 has introduced some new features to provide better cross-platform
button placement. For example, on a Mac, an "accept" button is placed to
the right of a "reject" button whereas on Windows, the reverse is true.
For me (a Mac user), seeing a Cancel or reject button to the right of an
OK or accept button is like seeing a red light on the bottom of a
traffic signal. :)
In the coming days, I will be changing all code to use the new API. This
message provides a brief overview. More datails can be found on the Qt
4.2 QDialogButtonBox and QMessageBox doc pages.
When using the new StandardButtons API with QMessageBox or placing a
QDialogButtonBox in dialog layouts, Qt will size and position buttons
according to the platform. In some cases, even the name is adjusted; for
example, "Discard" is "Don't Save" on a Mac.
The API uses the StandardButton enum instead of button names in
parameters. OK, Open and Save are "accept" buttons and Cancel, Close and
Abort are "reject" buttons. Eighteen buttons are predefined and it is
also possible to create a custom labeled button, assign it a role and
then add it to the dialog. The default and escape buttons are also
selected based upon a button's role.
The old API used a zero based index and looked like this:
int ret = QMessageBox::warning(this, "Title", "Message", "Ok", "Cancel");
if (ret == 0) okAction();
The new API uses an enum and looks like this:
QMessageBox::StandardButton ret = QMessageBox:warning(this, "Title",
"Message", QMessageBox::Ok | QMessageBox::Cancel);
if (ret == QMessageBox::Ok) okAction();
Buttons in the new API are 'or'ed together rather then listed in
separate parameters since button order is determined by the platform
based upon each buttons role.
Tom
More information about the Qgis-developer
mailing list