Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
[Solved] Custom Layout plugin for Qt Designer does not work
Bekos last edited by
I am trying to create a custom plugin for QtDesigner, but I fail so far.
I wanted a layout that, when it's resized, it preserves the aspect ratio of its attached children. Using an online tutorial of how to make custom layouts I finaly did it and it works. But now I want to be able to use this custom layout from inside the QtDesigner. So, I created a new MSVC2008 project using the "Qt4 Designer Plugin" template. This template generates a lot of code. As you already know it creates a plugin class that inherits from QObject and QDesignerCustomWidgetInterface classes. In this code I changed only 2 functions:
- I changed the "isContainer()" function to return true.(but I also tried it with false)
- And I changed the createWidget() function. Here I had an other problem. This function returns a QWidget* while I want to create a CustomLayout* (which inherits QLayout). The only solution I could think of was to create a QWidget object and use "setLayout()" function to set on it my CustomLayout class object. And then return the QWidget object. Is this the right solution? here is my code:
QWidget CustomLayoutPlugin::createWidget(QWidget parent)
CustomLayout layout = new CustomLayout(parent);
QWidget widget = new QWidget(parent);
After those 2 changes I compiled it, I took the debug and release lib and dlls files and I placed them under the "<QtFolder>\plugins\designer" path. So far so good. Now my CustomLayout appears in the toolbox of the QtDesigner but I have the following problems:
- When I click on the Layout to drag it on the form I get this message: "A class name mismatch occurred when creating a widget using the custom widget factory registered for widgets of class CustomLayout. It returned a widget of class QWidget"
- Regardless the message above, I can place the CustomLayout on the form but it does not seem to work. The widgets I attach to it do not move/resize/stretch at all. Like there is no Layout. Btw: The Class name at the Object inspector is QWidget and there is no CustomLayout attached to it.
What am I doing wrong? Thank you for your time.
sigrid last edited by
Designer currently does not support using custom layout plugins. Adding support for it is listed as a suggestion for Qt 5.0 "here":http://bugreports.qt.nokia.com/browse/QTBUG-3109
Feel free to use the link above to vote for the suggestion.
Bekos last edited by
Thanks for letting me know that this is not possible in the current version!
[quote author="sigrid" date="1306498691"]Designer currently does not support using custom layout plugins. Adding support for it is listed as a suggestion for Qt 5.0 "here":http://bugreports.qt.nokia.com/browse/QTBUG-3109
Feel free to use the link above to vote for the suggestion.[/quote]