Results 1 to 5 of 5

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Similar Threads

  1. Custom widget
    By zorro68 in forum Qt Programming
    Replies: 7
    Last Post: 28th January 2008, 14:06
  2. Replies: 12
    Last Post: 15th February 2006, 10: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.