Results 1 to 2 of 2

Thread: Qt Designer - expose child widget in Custom Container Widget Plugin

  1. #1
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Qt Designer - expose child widget in Custom Container Widget Plugin

    I have a custom widget I've made. It consists of a custom QPushButton and a QFrame in a vertical layout. Within the QFrame is a QWidget used as a container. Click the button to toggle the visibility of the widget inside the frame and the frame will resize. This creates a nice expanding widget. I can use this widget without problems programmatically, but I want to design in a WYSIWYG manner, so I need to create a QtDesigner plugin.

    I've created a small test widget, MyWidget, that mimics the above. It has a button and a widget in a vertical layout. The plugin, mywidgetplugin returns true for isContainer(). I can see and place MyWidget inside Qt Designer and place widgets onto MyWidget. While this is cool, it's not the exact functionality I need. I need to be able to place widgets onto the container widget inside MyWidget (see attached image).

    mywidget_diagram.png

    Does anybody know how to expose a child widget of a custom widget via a plugin so Qt Designer can see it as a viable container?

    I was hacking around and I tried this...it almost works until it crashes Designer when I click and drag the mouse over the container widget. (probably because I'm doing something stupid, but I don't know enough programming to avoid it). It also doesn't save properly because when I reopen the ui file the original container widget (with all the new checkboxes/radio buttons/etc inside) is now just a free floating child of MyWidget, and MyWidget has its own clean container widget. This probably has something to do with *child pointer and how MyWidget gets recreated when I reload the ui file, but I don't know enough to troubleshoot this.

    My Widget:
    Qt Code:
    1. MyWidget::MyWidget(QWidget *parent) :
    2. QWidget(parent)
    3. {
    4. QVBoxLayout *layout = new QVBoxLayout(this);
    5. QPushButton *button = new QPushButton();
    6. button->setObjectName("__qt__passive_button");
    7. QWidget *containerWidget = new QWidget();
    8. containerWidget->setObjectName("container");
    9. layout->addWidget(button);
    10. layout->addWidget(containerWidget);
    11.  
    12. }
    To copy to clipboard, switch view to plain text mode 

    Here's the hack to the plugin:
    Qt Code:
    1. void MyWidgetPlugin::initialize(QDesignerFormEditorInterface *formEditor)
    2. {
    3. if (m_initialized)
    4. return;
    5.  
    6. // Add extension registrations, etc. here
    7.  
    8. manager = formEditor->formWindowManager();
    9. qDebug() << manager;
    10.  
    11. m_initialized = true;
    12. }
    13.  
    14. bool MyWidgetPlugin::isInitialized() const
    15. {
    16. return m_initialized;
    17. }
    18.  
    19. QWidget *MyWidgetPlugin::createWidget(QWidget *parent)
    20. {
    21. QWidget *myWidget = new MyWidget(parent);
    22.  
    23. if (manager)
    24. formWindow = manager->formWindow(0);
    25.  
    26. QWidget *child = myWidget->layout()->itemAt(1)->widget();
    27. if (formWindow)
    28. formWindow->manageWidget(child);
    29.  
    30. return myWidget;
    31. }
    To copy to clipboard, switch view to plain text mode 

    Here is an image comparing before and after the hack. I'd like to be able to do what is in the right image legitimately if Qt Designer allows. I found this old post that seems to imply it might not be possible:

    http://www.qtcentre.org/threads/1697...ight=container

    Any help would be much appreciated. I would much rather setup my little widgets in a WYSIWYG fashion than by programming.

    Kevin
    Attached Images Attached Images

  2. #2
    Join Date
    Mar 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Qt Designer - expose child widget in Custom Container Widget Plugin

    I found a solution using the multipagewidgetplugin for MyWidget, but treating it as only a 1 page widget. I tested it in PyQt at work. I'll post a longer response with code when I get home tonight. I had tried this approach before, but I didn't fully understand what was happening...now I think I do.

    -Kevin

Similar Threads

  1. Replies: 2
    Last Post: 9th December 2010, 15:11
  2. Custom Container widget plugin help needed
    By JohnKustrin in forum Newbie
    Replies: 1
    Last Post: 14th May 2010, 11:01
  3. Replies: 1
    Last Post: 6th May 2010, 11:09
  4. Replies: 4
    Last Post: 5th March 2010, 15:20
  5. Replies: 4
    Last Post: 9th August 2007, 09:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.