Results 1 to 5 of 5

Thread: [4.1.1] Custom Widget visible in Edit but not in Preview

  1. #1
    Join Date
    Mar 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [4.1.1] Custom Widget visible in Edit but not in Preview

    Fedora Core 3, QT 4.1.1, gcc

    Hi!

    This is my first start in producing a custom widget: 'AnAusWidget' to use it in Designer 4.1.1.

    The 'funny' thing is, that I can see my AnAusWidget in Editor mode, but when I go into preview mode the widget ist not there (kind of). AnAusWidget ist just a Widget produced in Designer holding one Button and a SpinBox with a simple connection between these two.

    I tested two things to see, if it is really not there:

    1. Into the Widget where I put in the AnAusWidget (by drag'n'drop) I put a QTextEdit above and one below and used VerticalLayout in the Widget to let the QTextEdit widgets expand sizing.
    In Edit Mode I can see me AnAusWidget between the the two QTextEdits.
    But wenn i go into Preview Mode the two QTextEdits expand into the area, where my AnAusWidget was located before..... is there a problem in the calculation how much space my AnAusWidgets wants?

    2. I set the space for my AnAusWidget to FIXED/FIXED with space 200,200. Now in Preview the space is left free between the QTextEdits. Even the ToolTip for my AnAusWidget is show, but the AnAusWidget ist not.

    Please see the attached ScreenShots

    Please have a look at the code:
    Qt Code:
    1. // File: an_aus.h
    2. #include "ui_an_aus.h"
    3. #include <QWidget>
    4.  
    5. class AnAusWidget : public QWidget
    6. {
    7.  
    8. Q_OBJECT
    9.  
    10. public:
    11. AnAusWidget(QWidget *parent = 0);
    12. virtual QSize minimumSizeHint () const;
    13.  
    14. private:
    15. Ui::an_aus _ui;
    16. };
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // File: an_aus.cpp
    2. #include "an_aus.h"
    3. #include "ui_an_aus.h"
    4.  
    5. AnAusWidget::AnAusWidget(QWidget *parent)
    6. : QWidget(parent)
    7. {
    8. _ui.setupUi(this);
    9. qDebug("Constructor of Widget was called");
    10. qApp->beep();
    11. }
    12.  
    13. QSize AnAusWidget::minimumSizeHint() const
    14. {
    15. return QSize(100,100);
    16. qDebug("SizeHint was called");
    17. }
    To copy to clipboard, switch view to plain text mode 

    The qDebug("Constructor ...") is called twice: start of dragging and after drop in edit mode. But never called in Preview... ?

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

    Qt Code:
    1. // File: an_aus_plugin.cpp
    2. #include "an_aus_plugin.h"
    3. #include "an_aus.h"
    4.  
    5. #include <QtPlugin>
    6.  
    7.  
    8. AnAusPlugin::AnAusPlugin(QObject *parent)
    9. : QObject(parent)
    10. {
    11. initialized = false;
    12. }
    13.  
    14. void AnAusPlugin::initialize(QDesignerFormEditorInterface *)
    15. {
    16. if (initialized) return;
    17. initialized = true;
    18. }
    19.  
    20. bool AnAusPlugin::isInitialized() const
    21. {
    22. return initialized;
    23. }
    24.  
    25. QWidget *AnAusPlugin::createWidget(QWidget* parent)
    26. {
    27. return new AnAusWidget(parent);
    28. }
    29.  
    30. QString AnAusPlugin::name() const
    31. {
    32. return "AnAus";
    33. }
    34.  
    35. QString AnAusPlugin::group() const
    36. {
    37. return "Display Widgets [Examples]";
    38. }
    39.  
    40. QIcon AnAusPlugin::icon() const
    41. {
    42. return QIcon();
    43. }
    44.  
    45. QString AnAusPlugin::toolTip() const
    46. {
    47. return "";
    48. }
    49.  
    50. QString AnAusPlugin::whatsThis() const
    51. {
    52. return "";
    53. }
    54.  
    55. bool AnAusPlugin::isContainer() const
    56. {
    57. return false;
    58. }
    59.  
    60. QString AnAusPlugin::domXml() const
    61. {
    62. // return "";
    63.  
    64. return "<widget class=\"AnAus\" name=\"an_aus\">\n"
    65. " <property name=\"geometry\">\n"
    66. " <rect>\n"
    67. " <x>0</x>\n"
    68. " <y>0</y>\n"
    69. " <width>100</width>\n"
    70. " <height>100</height>\n"
    71. " </rect>\n"
    72. " </property>\n"
    73. " <property name=\"toolTip\" >\n"
    74. " <string>AnAusSchalter</string>\n"
    75. " </property>\n"
    76. " <property name=\"whatsThis\" >\n"
    77. " <string>Nur so mal ein Test "
    78. "wie PLUGINs funktionieren.</string>\n"
    79. " </property>\n"
    80. "</widget>\n";
    81.  
    82. }
    83.  
    84. QString AnAusPlugin::includeFile() const
    85. {
    86. return "an_aus.h";
    87. }
    88.  
    89. QString AnAusPlugin::codeTemplate() const
    90. {
    91. return "";
    92. }
    93.  
    94. Q_EXPORT_PLUGIN2(customwidgetplugin, AnAusPlugin)
    To copy to clipboard, switch view to plain text mode 

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


    To compile I used:
    qmake an_aus_plugin.pro
    make
    su -c "make install"


    I would be glad about any comment.

    Kind regards,
    Michael
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [4.1.1] Custom Widget visible in Edit but not in Preview

    I am having the same problem. Not sure why? Does anyone have a solution to this problem? My setup is the same .

  3. #3
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [4.1.1] Custom Widget visible in Edit but not in Preview

    I did some testing, and the custom widgets show when you compile and run a form using the custom widget, it simply doesn't show up in designer->preview

  4. #4
    Join Date
    Jan 2006
    Posts
    30
    Thanks
    3
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: [4.1.1] Custom Widget visible in Edit but not in Preview

    You should be seeing two problems here. 1) Any container widget you create should not actually accept items to "contain." 2) All widgets should not work in Preview mode.

    Here is the solution. Your widget naming scheme is not consistant.

    in you doXml function, you use this:
    Qt Code:
    1. return "<widget class=\"AnAus\" name=\"an_aus\">\n"" <property name=\"geometry\">\n"
    To copy to clipboard, switch view to plain text mode 

    when in fact it should be
    Qt Code:
    1. return "<widget class=\"AnAusWidget\" name=\"AnAus\">\n"" <property name=\"geometry\">\n"
    To copy to clipboard, switch view to plain text mode 

    That class name should be the name of the class you are trying to make custom. More specifically, what ever you return in the creatWidget function, you should use here. In your case, you are returning a

    Qt Code:
    1. AnAusWidget (parent)
    To copy to clipboard, switch view to plain text mode 

    so you class name should be

    Qt Code:
    1. <widget class=\"AnAusWidget\"
    To copy to clipboard, switch view to plain text mode 

    Your name can be what ever you want, but it has to match what you put in the plugin::name function. You put

    Qt Code:
    1. return "AnAus";
    To copy to clipboard, switch view to plain text mode 

    So your name in the doXml should be

    Qt Code:
    1. name=\"AnAus\"
    To copy to clipboard, switch view to plain text mode 

    Finally, you should change this

    Qt Code:
    1. Q_EXPORT_PLUGIN2(customwidgetplugin, AnAusPlugin)
    To copy to clipboard, switch view to plain text mode 

    to something like this:

    Qt Code:
    1. Q_EXPORT_PLUGIN2(AnAus_v1, AnAusPlugin)
    To copy to clipboard, switch view to plain text mode 

    Make this as specfic as possible, otherwise Designer gets two of the same plugin "TARGET" names, and can't figure out which one to use.

    I made the same exact mistakes, and this was the solution for me.

  5. #5
    Join Date
    Mar 2006
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: [4.1.1] Custom Widget visible in Edit but not in Preview

    Dear rianquinn,

    thank you for your information.

    I tried you changes and the did no work. However they brougth me to the right track:

    I had to change:
    Qt Code:
    1. QString AnAusPlugin::name() const
    2. {
    3. return "AnAusWidget"; // b/c I create a AnAusWidget ... before was: return "AnAus";
    4. }
    To copy to clipboard, switch view to plain text mode 

    and in
    doXml

    Qt Code:
    1. .....
    2. return "<widget class=\"AnAusWidget\" name=\"an_aus\">\n"
    3. .....
    To copy to clipboard, switch view to plain text mode 

    instead of
    Qt Code:
    1. .....
    2. return "<widget class=\"AnAus\" name=\"an_aus\">\n"
    3. .....
    To copy to clipboard, switch view to plain text mode 


    So the main problem was, that I gave the wrong name of the custom widget at these two places.



    Thanks again for pointing me in the right direction.
    Michael

Similar Threads

  1. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 15:06
  2. Replies: 12
    Last Post: 15th February 2006, 11:46

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.