Results 1 to 8 of 8

Thread: Apply Layout to custom widget plugin container

  1. #1
    Join Date
    May 2014
    Posts
    5
    Thanks
    2

    Default Apply Layout to custom widget plugin container

    Hello,

    I am trying to create a custom wigdet and provide it to qtcreator as a plugin. The widget is meant to be a frame, containing an icon and a title and should work as a container for other widgets. I created the widget's class + ui (ResultFrame) and the plugin class (ResultFramePlugin) as well. Everything works great so far. However, when I drag and drop the ResultFrame widget in a new project I cannot apply a layout to it. I can drag and drop other widgets to my ResultFrame widget. But the buttons for applying a layout stay disabled (see screenshot).

    So my question is: Is it possible to create a custom container plugin and apply a layout in another project after dragging and dropping the plugin widget to the ui? If so, what am I supposed to do, since just returning true for isContainer() seems not to work. Maybe I must implement a sizeHint for the ResultFrame widget or something like that? I dont have any good idea what I should try and I dont know, how to figure out what I am doing wrong. So I would be thankful, if anyone can give me a hint!


    Layout.PNG

    Here are some code snippets of the plugin class. If I left out any important information, please let me know.

    Qt Code:
    1. QWidget *ResultFramePlugin::createWidget(QWidget *parent)
    2. {
    3. return new ResultFrame(parent);
    4. }
    5.  
    6. bool ResultFramePlugin::isContainer() const
    7. {
    8. return true;
    9. }
    10.  
    11. QString ResultFramePlugin::domXml() const
    12. {
    13. return "<widget class=\"ResultFrame\" name=\"ResultFrame\">\n"
    14. " <property name=\"geometry\">\n"
    15. " <rect>\n"
    16. " <x>0</x>\n"
    17. " <y>0</y>\n"
    18. " <width>50</width>\n"
    19. " <height>50</height>\n"
    20. " </rect>\n"
    21. " </property>\n"
    22. " <property name=\"toolTip\" >\n"
    23. " <string>Frame</string>\n"
    24. " </property>\n"
    25. " <property name=\"whatsThis\" >\n"
    26. " <string>Frame widget</string>\n"
    27. " </property>\n"
    28. "</widget>\n";
    29. }
    To copy to clipboard, switch view to plain text mode 

    Thanks for any help,
    Alex

    Edit: Maybe I should mention the Qt version: I am using Qt5.3.1 and qtcreator 3.2.81.
    Last edited by Alex87; 27th July 2014 at 17:30.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Apply Layout to custom widget plugin container

    Hmm, looks right. Is the isContainer() method called?

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Alex87 (27th July 2014)

  4. #3
    Join Date
    May 2014
    Posts
    5
    Thanks
    2

    Default Re: Apply Layout to custom widget plugin container

    Hello anda_skoa,

    thank you for your quick reply!

    I implemented a QMessageBox inside the isContainer() method, which shows up when I open the ui-designer for the first time. So the method is called. Any other ideas, why it does not work as expected?

    Thanks for your help in advance!
    Last edited by Alex87; 27th July 2014 at 20:21.

  5. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Apply Layout to custom widget plugin container

    My guess would be a bug in designer.

    Cheers,
    _

  6. #5
    Join Date
    May 2014
    Posts
    5
    Thanks
    2

    Default Re: Apply Layout to custom widget plugin container

    Thank you for the input. I tried the plugin in qt-creator 3.0.1 and Qt 5.2.1, but the problem still remains . If anyone has build a container plugin, which accepts a layout, I woud be glad to know how it works.

  7. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Apply Layout to custom widget plugin container

    As a work around maybe using QDesignerContainerExtension? http://qt-project.org/doc/qt-5/qdesi...extension.html

    In any case it would be helpful to check the issue tracking system if the problem has been reported and report it if not.

    Cheers,
    _

  8. The following user says thank you to anda_skoa for this useful post:

    Alex87 (28th July 2014)

  9. #7
    Join Date
    May 2014
    Posts
    5
    Thanks
    2

    Default Re: Apply Layout to custom widget plugin container

    I tried QDesignerContainerExtension and it works well! Thank you for pointing me in the right direction! I read http://comments.gmane.org/gmane.comp....general/35506 and it is stated, that isContainer() only works for widget, which do not include any chidren. The suggested work around is the correct way to get a layout applied.

  10. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Apply Layout to custom widget plugin container

    Well, the last posting in the thread suggests that it should have worked for your frame

    For a simple container like QFrame that does not have internal children, it
    should be sufficient to return 'true' from
    bool QDesignerCustomWidgetInterface::isContainer (). The user drops child
    widgets directly onto those.
    Cheers,
    _

Similar Threads

  1. Replies: 2
    Last Post: 27th July 2011, 15:49
  2. Replies: 1
    Last Post: 23rd June 2011, 23:09
  3. Custom Container widget plugin help needed
    By JohnKustrin in forum Newbie
    Replies: 1
    Last Post: 14th May 2010, 10:01
  4. Problem with custom container widget
    By MrGarbage in forum Qt Tools
    Replies: 4
    Last Post: 25th August 2007, 03:37
  5. Replies: 4
    Last Post: 9th August 2007, 08: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.