1 Attachment(s)
Promoting a QDockWidget to a custom subclass in Designer
I made a custom QDockWidget subclass to handle some specific I/O tasks, but I am having some trouble placing it into a Qt Designer form (a QMainWindow based form).
Qt versions: 4.5.1 on Gentoo Linux, 4.5.2 on Mac OS X
Promoting the QDockWidget doesn't cause any complaints, but when I run my program, the widgets inside my custom dock widget do not appear. The generated code shows Qt is trying to set the contents of my widget to an empty QWidget (dockWidgetContents). Designer does not seem to let me get rid of this dockWidgetContents QWidget, but I can modify its properties. The attached example is for this scenario.
I tried making a plugin for Designer, but that seems like a lot of work just to place it in a form with Designer. Also, I seem to have failed some form of container widget aspect of creating plugins (domXml stuff that I'm supposed to put in).
Promoting the QWidget (dockWidgetContents) inside a generic QDockWidget on the main form has layout issues. The generated code seems to want to replace the layout that the QWidget version of my custom subclass already has. The runtime error is: QLayout: Attempting to add QLayout "" to CustomSubclass "ObjectName", which already has a layout
Any thoughts on how best to solve this issue? It seems strange that Qt Designer lets you put together custom QDockWidget based forms, but fails at letting QDockWidgets be promoted. I can live with the custom code solution, but it seems like the Designer should have a decent way to handle this.
Re: Promoting a QDockWidget to a custom subclass in Designer
Why exactly do you subclass QDockWidget? Shouldn't you be subclassing the class you put inside the dock widget instead?
Re: Promoting a QDockWidget to a custom subclass in Designer
That actually makes more sense than what I was doing. One reason I did not do that is when I attempted something similar I apparently did not change my subclass to inherit off of QWidget instead of QDockWidget (tried QDockWidget way first), which gave some strange dock widget inside a dock widget results.
I was also considering adding functionality to the dock widgets, since I plan to use them extensively. Although I suppose if I wanted to add functionality to the QDockWidgets, I should keep the QDockWidget functionality in a special subclass instead of involving functionality unrelated to the docking features. Sleep deprivation must be getting to me... :o
Re: Promoting a QDockWidget to a custom subclass in Designer
I think I understand what you were trying to do and know one reason you might want to do that is the ease of creating a dock widget in the designer (outside of the mainframe form) that you can reuse. Yeah, there are other ways of doing it, but that is the most intuitive (for me anyway).
In order to do what you are trying to do, call your QDockWidget sub-class setupUI (assuming you did the multiple-inheritance way of subclassing using designer forms) after the mainframe has done all its setupUi stuff, not in your sub-class's constructor.
That should do what you want.