Results 1 to 13 of 13

Thread: Insert custom widget in the qt designer list box

  1. #1
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Insert custom widget in the qt designer list box

    I created a custom plugin subclassing QWidget, then I created a plugin subclassing QDesignerCustomWidgetInterface and using this same header as an interface

    The plugin works correctly in both static and dynamic configurations if manually loaded by code, but I can't figure out how to show it into the Qt Designer's list box.

    I tried creating two classes like this example
    http://doc.trolltech.com/4.5/designe...extension.html
    but I failed, I tried to include a .pri file into the project but I failed too. I put the dll/lib files of my plugin into the C:\Qt\2010.04\qt\plugins\designer (I am under WinXp) but the plugin won't show up in the list box of the Qt Designer.

    Any suggestions? Tell me if a class' code is needed to paste, I can't figure out where's the problem

  2. #2
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Insert custom widget in the qt designer list box

    I'm not a Windows programmer, but if you can run designer from a console/terminal, it spews out all sorts of useful information on startup about various problems it encounters. Normally, it will provide you with clues about why your plugin is failing to load. If it doesn't, it means it isn't find it to begin with, but that's probably not the problem.

    Perhaps there's a designer startup log under Windows?

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert custom widget in the qt designer list box

    Please don't confuse "class" with "plugin". You should create a plugin containing an implementation of the QDesignerCustomWidgetInterface class (and appropriate plugin export macro as said in the docs). The class should return instances of a custom widget class. The plugin should be deployed in $QTDIR/plugins/designer directory.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert custom widget in the qt designer list box

    I missed the EXPORT macro. I just have to include it into the plugin declaration class right?

    Not into the base QWidget class, at least documentation seems telling this

    Regarding the plugin debugging i found this:
    set QT-DEBUG-PLUGINS=1 in your shell.
    But in Win32 I really don't know how to log this or where to insert it... Perhaps using qmake manually by console?

  5. #5
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert custom widget in the qt designer list box

    Update: added the export macro like following
    Qt Code:
    1. ...
    2. #include <QtDesigner/QDesignerExportWidget>
    3.  
    4. class QDESIGNER_WIDGET_EXPORT IconEditor : public QWidget
    5. {
    6. ...
    To copy to clipboard, switch view to plain text mode 

    If I compile only the custom widget project (not the plugin) I have a lot of errors:
    undefined reference to _imp__xxxx
    undefined reference to _imp__xxxx
    undefined reference to _imp__xxxx
    undefined reference to _imp__xxxx
    undefined reference to _imp__xxxx
    collect2: ld returned 1 exit status
    But if I compile the plugin project it succeeds. So I think I did it right.

    After compiling I find the iconeditorplugin.dll and libiconeditorplugin.a in the $QTDIR/plugins/designer (C:\Qt\2010.04\qt\plugins\designer to be precise). As documentation states.

    Then I open the Qt Creator and create a generic dialog GUI and I still can't find my plugin (it has everything I think, including icons and descriptions) in the list box. To clear every doubt about where I want to show my plugin, I am including this screenshot:

    - Screenshot -

    Regarding the QT-DEBUG-PLUGINS=1, I set the environment variable but where to see a debug log?? I can't find any errors anywhere.

    I'm a newbie to Qt (you probably would have got it yet) but I'm reading through all the documentation and still can't figure out how to solve

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert custom widget in the qt designer list box

    You need Q_EXPORT_PLUGIN macro to actually export the plugin. Do you have it?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert custom widget in the qt designer list box

    Yes, I'm pasting the content of the plugin files

    iconeditorplugin.cpp
    Qt Code:
    1. #include <QtPlugin>
    2.  
    3. #include "../iconeditor/iconeditor.h"
    4. #include "iconeditorplugin.h"
    5.  
    6. IconEditorPlugin::IconEditorPlugin(QObject *parent)
    7. : QObject(parent)
    8. {
    9. }
    10.  
    11. QString IconEditorPlugin::name() const
    12. {
    13. return "IconEditor";
    14. }
    15.  
    16. QString IconEditorPlugin::includeFile() const
    17. {
    18. return "iconeditor.h";
    19. }
    20.  
    21. QString IconEditorPlugin::group() const
    22. {
    23. return tr("Image Manipulation Widgets");
    24. }
    25.  
    26. QIcon IconEditorPlugin::icon() const
    27. {
    28. return QIcon(":/images/iconeditor.png");
    29. }
    30.  
    31. QString IconEditorPlugin::toolTip() const
    32. {
    33. return tr("An icon editor widget");
    34. }
    35.  
    36. QString IconEditorPlugin::whatsThis() const
    37. {
    38. return tr("This widget is presented in Chapter 5 of <i>C++ GUI "
    39. "Programming with Qt 4</i> as an example of a custom Qt "
    40. "widget.");
    41. }
    42.  
    43. bool IconEditorPlugin::isContainer() const
    44. {
    45. return false;
    46. }
    47.  
    48. QWidget *IconEditorPlugin::createWidget(QWidget *parent)
    49. {
    50. return new IconEditor(parent);
    51. }
    52.  
    53. Q_EXPORT_PLUGIN2(iconeditorplugin, IconEditorPlugin)
    To copy to clipboard, switch view to plain text mode 

    iconeditorplugin.h
    Qt Code:
    1. #ifndef ICONEDITORPLUGIN_H
    2. #define ICONEDITORPLUGIN_H
    3.  
    4. #include <QtDesigner/QDesignerCustomWidgetInterface>
    5.  
    6. class IconEditorPlugin : public QObject,
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. IconEditorPlugin(QObject *parent = 0);
    12.  
    13. QString name() const;
    14. QString includeFile() const;
    15. QString group() const;
    16. QIcon icon() const;
    17. QString toolTip() const;
    18. QString whatsThis() const;
    19. bool isContainer() const;
    20. QWidget *createWidget(QWidget *parent);
    21.  
    22.  
    23.  
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    iconeditor.h
    Qt Code:
    1. #ifndef ICONEDITOR_H
    2. #define ICONEDITOR_H
    3.  
    4. #include <QColor>
    5. #include <QImage>
    6. #include <QWidget>
    7. #include <QtDesigner/QDesignerExportWidget>
    8.  
    9. //QDESIGNER_WIDGET_EXPORT
    10. class QDESIGNER_WIDGET_EXPORT IconEditor : public QWidget
    11. {
    12. Q_OBJECT
    13. Q_PROPERTY(QColor penColor READ penColor WRITE setPenColor)
    14. Q_PROPERTY(QImage iconImage READ iconImage WRITE setIconImage)
    15. Q_PROPERTY(int zoomFactor READ zoomFactor WRITE setZoomFactor DESIGNABLE true)
    16.  
    17. public:
    18. IconEditor(QWidget *parent = 0);
    19.  
    20. void setPenColor(const QColor &newColor);
    21. QColor penColor() const { return curColor; }
    22. void setZoomFactor(int newZoom);
    23. int zoomFactor() const { return zoom; }
    24. void setIconImage(const QImage &newImage);
    25. QImage iconImage() const { return image; }
    26. QSize sizeHint() const;
    27.  
    28. protected:
    29. void mousePressEvent(QMouseEvent *event);
    30. void mouseMoveEvent(QMouseEvent *event);
    31. void paintEvent(QPaintEvent *event);
    32.  
    33. private:
    34. void setImagePixel(const QPoint &pos, bool opaque);
    35. QRect pixelRect(int i, int j) const;
    36.  
    37. QColor curColor;
    38. QImage image;
    39. int zoom;
    40. };
    41.  
    42. #endif
    To copy to clipboard, switch view to plain text mode 

    iconeditor.cpp
    Qt Code:
    1. #include <QtGui>
    2.  
    3. #include "iconeditor.h"
    4.  
    5. IconEditor::IconEditor(QWidget *parent)
    6. : QWidget(parent)
    7. {
    8. ...
    9. }
    10.  
    11. void IconEditor::setPenColor(const QColor &newColor)
    12. {
    13. curColor = newColor;
    14. }
    15.  
    16. void IconEditor::setZoomFactor(int newZoom)
    17. {
    18. ...
    19. }
    20.  
    21. void IconEditor::setIconImage(const QImage &newImage)
    22. {
    23. ...
    24. }
    25.  
    26. QSize IconEditor::sizeHint() const
    27. {
    28. ...
    29. return size;
    30. }
    31.  
    32. void IconEditor::mousePressEvent(QMouseEvent *event)
    33. {
    34. ...
    35. }
    36.  
    37. void IconEditor::mouseMoveEvent(QMouseEvent *event)
    38. {
    39. ...
    40. }
    41.  
    42. void IconEditor::paintEvent(QPaintEvent *event)
    43. {
    44. QPainter painter(this);
    45.  
    46. ...
    47. }
    48.  
    49. void IconEditor::setImagePixel(const QPoint &pos, bool opaque)
    50. {
    51. ... not relevant
    52. }
    53.  
    54. QRect IconEditor::pixelRect(int i, int j) const
    55. {
    56. ...
    57. }
    To copy to clipboard, switch view to plain text mode 


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


    And resources are okay in a qrc file. Why the plugin still can't load?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert custom widget in the qt designer list box

    Run Designer and choose Help/About plugins from the menu. You'll see a reason why your plugin is failing.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert custom widget in the qt designer list box

    Maybe I'm looking at the wrong window but I can't see other plugin options


    Uploaded with ImageShack.us

  10. #10
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Insert custom widget in the qt designer list box

    Your plugin isn't showing up at all. This indicates that designer doesn't see it. It's probably in the wrong directory. If you installed a new or upgraded version of Qt recently, you may have two seperate installations or partial installations and plugins are being installed in the wrong one.

    If your plugin was found but failed to load properly, the window would list reasons for the failure. If it doesn't show up at all, it isn't being found.

  11. The following user says thank you to SixDegrees for this useful post:

    eg3gg (6th September 2010)

  12. #11
    Join Date
    Sep 2010
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert custom widget in the qt designer list box

    You are right, there was another "designer" directory.

    Now the error is "The plugin .../iconeditorplugin.dll uses incompatible Qt library. Expected build key "Windows msvc release full-config", got "Windows mingw release full-config"

    Does this mean I need to compile that necessarily with visual studio?

  13. #12
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Insert custom widget in the qt designer list box

    Yes, you need to compile the plugin with the same compiler as the host program.
    This has to do with symbolic names etc... in the compiled binaries.

    In other words, mingw and msvc speak different languages.

  14. #13
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert custom widget in the qt designer list box

    Yes. Or you can use Designer (and Qt) built with MinGW.

    Please don't use 3rd party sites for storing images. Use the forum attachment feature instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 20th August 2010, 13:20
  2. Replies: 1
    Last Post: 6th May 2010, 10:09
  3. How can I create a widget list as Qt Designer?
    By ricardo in forum Qt Programming
    Replies: 5
    Last Post: 3rd May 2009, 12:54
  4. Custom widget in list view
    By fusoin23 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 14:09
  5. Custom widget + Qt Designer
    By chombium in forum Qt Tools
    Replies: 1
    Last Post: 12th April 2006, 20:33

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.