Skip to main content
December 3, 2013
Question

Modal dialogs in plug-in with QT

  • December 3, 2013
  • 2 replies
  • 3394 views

Hi,

We are trying to create a modal dialog in Illustrator CS6 plug-in using Qt.

But when we call QDialog::exec() method, dialog appears but it is not modal, we can interact with panels (move them, select colors from palette and so on).

The code that we are using looks like:

static HWND mainHWND = ::FindWindow(NULL, L"Adobe Illustrator CS6");

MyDialog *dialog = new MyDialog(new QWinWidget(mainHWND));

dialog->exec();

or simply

QMessageBox::about(new QWinWidget(mainHWND), "title", "text");

In both cases dialog and message box are not modal.

The only way to create a custom modal dialog we have found is using Flash, but it is not acceptable for us.

Could you suggest how to do this with Qt?

Thanks!

This topic has been closed for replies.

2 replies

panduvittala
Inspiring
December 16, 2013

Below code worked for me.

sAIAppContext->GetPlatformAppWindow(&hwndref); // <-- this does not work on mac

QWinWidget *qwin=new QWinWidget(hwndref);

QDialog *dlg=new QDialog(qwin);

dlg->setModal(true);

dlg->show();

A. Patterson
Inspiring
December 3, 2013

You need to make sure you're parenting off the right handle. The main window you want to parent off is called 'illustrator'. We have code that goes looking for it the first time it's requested and then after that it caches the handle since it obviously isn't going anywhere until Illustrator closes.

This is how we figured out which handle to use:

  1. Fire up Spy++ and find the Illustrator family of handles.
  2. Put a breakpoint in your code where you create the MyDialog object and try different handles you read manually from Spy++.
  3. When you find the one that works, just figure out how to use Win32 calls to get the right handle. You can verify that again using Spy++.
December 9, 2013

Thanks for your reply.

We have tried the suggested method and looked over all windows in the Illustrator process, but still can't create a dialog, that would block all Illustrator UI.

At best (when we are parenting from a window with the class name 'illustrator') we can create a dialog, that blocks the main window (all menus and tools), but panels are still not blocked i.e. we can move them and select tools from them (see video http://screencast.com/t/3e82I118).

Do you have any other idea how to block them?

Have you managed to block them using your method?

A. Patterson
Inspiring
December 10, 2013

Yes, we set 'setModal(true)' manually too, and we tried this combinations of flags, nothing helps.

There is a function in Acrobat API called AVAppBeginModal, that "Prepares the Acrobat viewer to display a modal window.

For example, it disables floating windows in Windows, where they are not automatically disabled."

May be there is some analog in Illustrator and your base class calles it?


On Mac, we have to call something that turns off the menus, but not in Windows.

I've just re-checked all our code and I can't find anything. We have a base class for modal dialogs, but there's nothing in there that does anything Illustrator-specific. It just sets the modality and handles a bunch of things like restoring & saving dialog geometry (to remember positioning) and other little hacks/tweaks for things I'm 100% sure aren't related to modality.


We have a singleton class derived from CWinWidget that represents the main application window. It doesn't have much at all frankly, it mostly looks like it exists to figure out which window to use as its base handle when creating itself and then is a singleton so it doesn't have to keep doing that.

I looked at our QApplication-derived class, and again, lots of Mac code but not a lot of Windows stuff. It doesn't have anything either. It looks like so long as we have picked up the right Illustrator window handle for our QWinWidget, it just works on Windows.