[PyQt] QMainWindow.restoreState does not restore docked widget

Baz Walter bazwal at ftml.net
Fri Apr 4 06:06:15 BST 2014


On 04/04/14 02:05, Thomi Richards wrote:
> Hi,
>
> I'm having difficulties making my main window restore my dock widget
> correctly. I've produced a minimal complete example to demonstrate my
> problem. The minimal example is still 73 lines long, which is perhaps a
> little long to include in an email in full. I'll post a link to it, and
> then quote snippets thereafter.
>
> The example is at: http://paste.ubuntu.com/7201238/
>

You're making two mistakes:

(1) failing to add the dock-widget to a (default) dock-area
(2) trying implement your own toggle view action

Qt already has (2) covered, and does a much better job of it than your 
example code currently does (for one thing, it handles closing of the 
dock-widget by the user).

So comment out *all* the toggle_dock_widget_action code in your example 
(including the signal handler), and put the following in initUI:

         self.filter_widget = MyDockWidget()
         self.addDockWidget(QtCore.Qt.RightDockWidgetArea, 
self.filter_widget)
         self.toggle_dock_widget_action = 
self.filter_widget.toggleViewAction()
         self.toggle_dock_widget_action.setText('Show/Hide Filter Pane')
         self.toolbar.addAction(self.toggle_dock_widget_action)

-- 
Regards
Baz Walter


More information about the PyQt mailing list