PDA

View Full Version : DockWidgets problem



faldzip
29th January 2009, 16:04
Hi!
I have an application with 3 dock widgets in it's QMainWindow. Dock widgets are only closable and each of them has only one allowed area. They are connected with checkable actions in menu like this:


connect(ui.actionProject_Explorer, SIGNAL(toggled(bool)), projectExplorerWidget, SLOT(setVisible(bool)));
connect(projectExplorerWidget, SIGNAL(visibilityChanged(bool)), ui.actionProject_Explorer, SLOT(setChecked(bool)));

So dock widget can be closed with X button or with unchecking action. There are two problems:
1. When I change size of a dock widget (with a mouse, during runtime), then close it and show it again, it has an initial size, no the size I set with mouse. How can I force them to remember that?

2. When I have some of those dock widgets visible and then minimize my app and restore, all dock widgets are always closed, even if they were visible before minimizing :/ How can I keep the state which was before minimizing?

I have tested my app on Vista and Kubuntu 8.04 and it works same on both platforms.

faldzip
30th January 2009, 17:13
Any ideas?

ToddAtWSU
30th January 2009, 18:47
1. When I change size of a dock widget (with a mouse, during runtime), then close it and show it again, it has an initial size, no the size I set with mouse. How can I force them to remember that?

You could make the dock widgets members of your class, and also keep variables that store the width and height of each dock widget. Then capture the "closing" or "hiding" of each dock widget and store its size before closing it. Then when it reappears, just resize it with the values you stored in your class.


2. When I have some of those dock widgets visible and then minimize my app and restore, all dock widgets are always closed, even if they were visible before minimizing :/ How can I keep the state which was before minimizing?
Maybe store bools in your class if the dock widgets are visible again changing the state to false when you close them and true when you open them.

One thing to maybe keep in mind if it's possible is are you destroying the dock widget when you close it or just hiding the dock widget so its the same object when you reshow it? If you are destroying them upon closing them, this would explain why their behavior changes from time to time, because you create a whole new dock widget that has no knowledge of its predecessor.

faldzip
30th January 2009, 19:38
One thing to maybe keep in mind if it's possible is are you destroying the dock widget when you close it or just hiding the dock widget so its the same object when you reshow it? If you are destroying them upon closing them, this would explain why their behavior changes from time to time, because you create a whole new dock widget that has no knowledge of its predecessor.


As I wrote in first post, I connect toggled(bool) with setVisible(bool) so I think I'm just hiding and showing and it's not destrying it.

ToddAtWSU
30th January 2009, 20:15
Have you verified that you are or when you are getting into these slots either by setting a break point or a print statement?

faldzip
30th January 2009, 20:37
OK, i found solution for problem 2. I have to add to my menu a QDockWidget::toggleViewAction() instead of creating my own actions.