wrongusername
wrongusername

Reputation: 18918

Forcing QDialog to stay open

How should I best go about forcing a QDialog to stay open when the dialog's accept() slot is called? I was thinking of reimplementing that function to get the dialog's exec to return without hiding the dialog, but was wondering if there were any better ways to accomplish this.

Upvotes: 1

Views: 1441

Answers (2)

alexisdm
alexisdm

Reputation: 29896

You need to make your QDialog modeless, by calling show instead of exec, and using a custom signal instead of accept, because accept closes the window. And you connect that signal to a slot in the main window with the code you had after the exec call.

And in case that wasn't already the case, you should keep a reference/pointer to your QDialog somewhere (as a member in your main window class, or a static variable within the function that opens it) to be able to avoid creating multiple instances of the dialog, and you need to make sure you only connect the signals/slots once.

Upvotes: 2

ccozad
ccozad

Reputation: 1129

Rather than use a QDialog, I would accomplish the effect with a QDockWidget.

  • Remove the feature that allows the dock to be moved (QDockWidget::DockWidgetMovable)
  • Set the dock widget to floating (setFloating(true))
  • Connect items on the dock widget to the appropriate signals and slots on the main window

References

Upvotes: 2

Related Questions