Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

Using Existing Dialogs with QMotifDialog

[ Previous: Using Custom QDialogs ] [ Home ] [ Next: Using Qt Main Window Classes ]

As mentioned earlier, the Print dialog cannot be replaced until we have converted the View widget. The Print dialog will be removed once we have finished our migration, since we will use QPrinter instead. Based on this information, we decide that it is not worth replacing the Print dialog with a custom QDialog replacement. Instead, we will keep the Motif based dialog and use QMotifDialog to integrate the dialog with the application.

Modality Requirements

Modality with QDialog is different from Motif. The QDialog::exec() function does not return until the dialog is finished. In Motif, modality is simply a property of the shell, and the application programmer must write QDialog::exec() style functionality if they want that behavior.

Since we will be using QMotifDialog (which is a QDialog subclass), we will need to have an accept and a reject callback for each dialog we integrate with QMotifDialog. The predefined Motif dialogs have these already: the XmNokCallback and XmNcancelCallback callbacks. However, the Print dialog only has an accept callback (the XmdNprintCallback), but it does not have a reject callback. We need to add this.

This is easily done. We add an XtCallbackList for the XmNcancelCallback callback in Xmd/PrintP.h:

We add the XmNcancelCallback callback to the list of resources for the XmdPrint widget class in Xmd/Print.c:

We need to activate this callback whenever we unmanage the widget and do not activate the print callback, which is in the do_help_cb() function:

... and in the unmanage_cb() function:

Integrating the Print Dialog

Now that the Print dialog has the appropriate accept and reject callbacks, we can use QMotifDialog. First we need to include the QMotifDialog header in todo.cpp.

We add a ShowPrintDialog() function which will create and execute the print dialog.

We change the Print menu item callback to call the new ShowPrintDialog() function. We pass the top-level QMotifWidget, which we will use as the parent for the dialog.

The ShowPrintDialog() function creates the Print dialog and executes it. We use the XmdNprintCallback callback to accept the dialog and the XmNcancelCallback callback to reject the dialog. We can do this easily by using the QMotifDialog::acceptCallback() and QMotifDialog::rejectCallback() functions, respectively. We also ensure that the print callback continues to call the Print() function as before.

After we build the project, the application runs and operates as expected. There is no visual or behavioral difference, even though the Print dialog is using QMotifDialog.

[ Previous: Using Custom QDialogs ] [ Home ] [ Next: Using Qt Main Window Classes ]

Copyright © 2005 TrolltechTrademarks
Qt 3.3.7