Announcements

Between mid-October and November, the content on AREA will be relocated to the Autodesk Community M&E Hub and the Autodesk Community Gallery. Learn more HERE.

Open and close a qwidget dialog in a utility Plugin

Open and close a qwidget dialog in a utility Plugin

rodbrew2
Contributor Contributor
586 Views
4 Replies
Message 1 of 5

Open and close a qwidget dialog in a utility Plugin

rodbrew2
Contributor
Contributor

What is the proper way to open and close a qwidget dialog window in a utility plugin?  I currently have the dialog open but when I close it it goes away but if I move off the Utilities tab and back again it will pop up again.  So somehow it is not closing correctly.  I haven't found a good modal window using qwidget in the sdk so I'm kind of winging it.

 

Thanks for any help.

0 Likes
587 Views
4 Replies
Replies (4)
Message 2 of 5

rodbrew2
Contributor
Contributor

Looking a little farther into this it's not so much closing the qwidget window as it is destroying the utility itself when the X on the qwidget window is pressed.  I'm not sure how to tie those two together.  I hope this makes sense.

0 Likes
Message 3 of 5

Bendo_
Community Visitor
Community Visitor

Doesn't deleting your qwindow is enough ?

Supposing your window is named "MyWindow"

class MyWindow(QWindow):
    def __init__(self, ...):
        # your stuff here

    def closeEvent(self, *args):
        del self

 

0 Likes
Message 4 of 5

rodbrew2
Contributor
Contributor

Hey Bendo I'm thinking it's not the qwidget window that's the problem it's actually shutting down the Utility plugin itself that seems to be missing.  For instance if I add a button for the plugin on the Utility panel and press it the UI comes up and the button remains pressed.  If I close the UI the button remains pressed.  If I cycle it again the UI comes up as normal.  If I don't unpress and navigate away from the utility panel and then back the button is still blue and the UI pops up again.  I guess this is kind of expected as it does it with a normal rollout.  A good example of the behavior I'm looking for is the Polygon Counter utility but with the qwidget.

0 Likes
Message 5 of 5

rodbrew2
Contributor
Contributor

Ok I think I got something figured out.  Not sure if it's the best way but it seems to work.  I added a closeEvent to my main UI in which I call the closeUtility function for my instance of the Utility plugin.  I also have a flag that keeps track of whether the UI dialog is open of not.  Like I said I'm not sure if this is the ideal way but it seems to work.

 

void Utility::BeginEditParams(Interface* ip, IUtil* u)
{
	this->iu = u;
	this->ip = ip;

	if (dialogOpen == FALSE)
	{
		dialog = new UtilityUI_Main;

		dialog->setWindowModality(Qt::WindowModal);

		dialog->show();

		dialogOpen = TRUE;
  }
	u->CloseUtility();
}

void UtilityUI_Main::closeEvent(QCloseEvent* event)
{
	if (myUtility.iu)
		myUtility.iu->CloseUtility();
	dialogOpen = false;
}

 

0 Likes