Results 1 to 2 of 2

Thread: How to add custom widget plugin in Designer's widget box? - Help

  1. #1
    Join Date
    Apr 2010
    Location
    Bahamas
    Posts
    29
    Thanks
    3
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default How to add custom widget plugin in Designer's widget box? - Help

    Hi,

    I've followed this tutorial http://web.mit.edu/qt-dynamic/www/de...getplugin.html to create my own customized widget. After doing the "make" and "make install" I've seen a library file created in my workspace and as well as in the /designer directory. However when I reload the designer, I don't see my custom widget in the widget box. Please help, these are the things that I've accomplished so far.

    The .pro file.

    Qt Code:
    1. CONFIG += designer \
    2. plugin \
    3. debug_and_release
    4. TEMPLATE = lib
    5. HEADERS += QCustomDialog.h \
    6. QCustomDialogPlugin.h
    7. SOURCES += QCustomDialog.cpp \
    8. QCustomDialogPlugin.cpp
    9.  
    10. target.path = $$[QT_INSTALL_PLUGINS]/designer
    11. INSTALLS += target
    To copy to clipboard, switch view to plain text mode 

    Here's my custom widget plugin.

    Qt Code:
    1. #ifndef QCUSTOMDIALOGPLUGIN_H
    2. #define QCUSTOMDIALOGPLUGIN_H
    3.  
    4. #include <QDesignerCustomWidgetInterface>
    5.  
    6. class QCustomDialogPlugin : public QObject, public QDesignerCustomWidgetInterface
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. QCustomDialogPlugin(QObject *parent = 0);
    12.  
    13. bool isContainer() const;
    14. bool isInitialized() const;
    15. QIcon icon() const;
    16. QString domXml() const;
    17. QString group() const;
    18. QString includeFile() const;
    19. QString name() const;
    20. QString toolTip() const;
    21. QString whatsThis() const;
    22. QWidget *createWidget(QWidget *parent);
    23. void initialize(QDesignerFormEditorInterface *core);
    24.  
    25. private:
    26. bool initialized;
    27. };
    28.  
    29.  
    30. #endif // QCUSTOMDIALOGPLUGIN_H
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. #include "QCustomDialogPlugin.h"
    2. #include "QCustomDialog.h"
    3. #include <QString>
    4. #include <QObject>
    5. #include <QtPlugin>
    6.  
    7. QCustomDialogPlugin::QCustomDialogPlugin(QObject *parent)
    8. : QObject(parent)
    9. {
    10. initialized = false;
    11. }
    12.  
    13. bool QCustomDialogPlugin::isInitialized() const
    14. {
    15. return initialized;
    16. }
    17.  
    18. QWidget *QCustomDialogPlugin::createWidget(QWidget *parent)
    19. {
    20. return new QCustomDialog(parent);
    21. }
    22.  
    23. QString QCustomDialogPlugin::name() const
    24. {
    25. return "QCustomDialog";
    26. }
    27.  
    28. QString QCustomDialogPlugin::group() const
    29. {
    30. return "Display Widgets [Examples]";
    31. }
    32.  
    33. QIcon QCustomDialogPlugin::icon() const
    34. {
    35. return QIcon();
    36. }
    37.  
    38. QString QCustomDialogPlugin::toolTip() const
    39. {
    40. return "";
    41. }
    42.  
    43. QString QCustomDialogPlugin::whatsThis() const
    44. {
    45. return "";
    46. }
    47.  
    48. bool QCustomDialogPlugin::isContainer() const
    49. {
    50. return true;
    51. }
    52.  
    53. QString QCustomDialogPlugin::domXml() const
    54. {
    55. return "<widget class=\"QCustomDialog\" name=\"customDialog\">\n"
    56. " <property name=\"geometry\">\n"
    57. " <rect>\n"
    58. " <x>0</x>\n"
    59. " <y>0</y>\n"
    60. " <width>400</width>\n"
    61. " <height>200</height>\n"
    62. " </rect>\n"
    63. " </property>\n"
    64. " <property name=\"toolTip\" >\n"
    65. " <string>The current time</string>\n"
    66. " </property>\n"
    67. " <property name=\"whatsThis\" >\n"
    68. " <string>Qt Custom Dialog "
    69. "the current time.</string>\n"
    70. " </property>\n"
    71. "</widget>\n";
    72. }
    73.  
    74. QString QCustomDialogPlugin::includeFile() const
    75. {
    76. return "QCustomDialog.h";
    77. }
    78.  
    79. Q_EXPORT_PLUGIN2(libCustomWidget, QCustomDialogPlugin)
    To copy to clipboard, switch view to plain text mode 

    I have not posted the widget class itself because I believe its already working. I've tried using it manually or without using the designer and it shows when run.

  2. #2
    Join Date
    Jan 2006
    Location
    Frankfurt
    Posts
    500
    Thanks
    1
    Thanked 52 Times in 52 Posts
    Platforms
    MacOS X Unix/X11

    Default Re: How to add custom widget plugin in Designer's widget box? - Help

    Open About Plugins in Designer/creator and see whether your library is already listed there. Then there should be an error message indicating that is going wrong.
    It's nice to be important but it's more important to be nice.

Similar Threads

  1. Replies: 4
    Last Post: 5th March 2010, 15:20
  2. Designer plugin widget property not recognized
    By janus in forum Qt Programming
    Replies: 7
    Last Post: 14th April 2009, 22:26
  3. Custom Widget Plugin
    By alisami in forum Qt Programming
    Replies: 2
    Last Post: 16th March 2009, 15:33
  4. Size of a plugin widget in designer
    By high_flyer in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2006, 14:29
  5. Managing widget plugin in Qt Designer
    By yellowmat in forum Newbie
    Replies: 8
    Last Post: 31st January 2006, 10:58

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.