May 27, 2011

Bekos Bekos
Lab Rat
34 posts

[Solved] Custom Layout plugin for Qt Designer does not work

 

Hello everyone!

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:
    1. QWidget *CustomLayoutPlugin::createWidget(QWidget *parent)
    2. {
    3.     CustomLayout* layout = new CustomLayout(parent);
    4.     QWidget* widget = new QWidget(parent);
    5.     widget->setLayout(layout);
    6.     return widget;
    7. }

    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.

Cheers!

2 replies

May 27, 2011

sigrid sigrid
Lab Rat
144 posts

Designer currently does not support using custom layout plugins. Adding support for it is listed as a suggestion for Qt 5.0 here [bugreports.qt.nokia.com]

Feel free to use the link above to vote for the suggestion.

May 27, 2011

Bekos Bekos
Lab Rat
34 posts

Thanks for letting me know that this is not possible in the current version!

Cheers!

sigrid wrote:
Designer currently does not support using custom layout plugins. Adding support for it is listed as a suggestion for Qt 5.0 here [bugreports.qt.nokia.com]

Feel free to use the link above to vote for the suggestion.

 
  ‹‹ Is MVC a way to a thin client-server application?      [SOLVED] addWidget determinded ››

You must log in to post a reply. Not a member yet? Register here!