Sunday, July 6th 2008, 12:35am UTC+1

You are not logged in.

  • Login
  • Register

Dear visitor, welcome to QtForum.org. If this is your first visit here, please read the Help. It explains how this page works. You must be registered before you can use all the page's features. Please use the registration form, to register here or read more information about the registration process. If you are already registered, please login here.

1

Thursday, April 10th 2008, 6:40pm

Why does my plugin widget not show?

Hi,
I started using QT4.3 on Linux about 3 months ago and I decided I need a plugin widget containing a LineEdit and a label. Nothing to difficult I thought.

I followed the tutorial and managed to have the plugin show in QT designer, I can drag the plugin widget into the design which shows as I intended it to show. When I do a preview, my custom widget doesn't show on the screen. Same when I compile, the widget won't show on the screen.

In QT designer, when I select my custom widget I get the following message :

A class name mismatch occurred when creating a widget using the custom widget factory registered for widgets of class SelectDateWidget. It returned a widget of class QWidget.

Could someone have a look at the code attached and see what I'm doing wrong?

Nb. After compiling the plugin I copy the generated libselectdatewidget.so to /usr/lib/qt4/plugins/designer.


Thanks,

Leo

customwidgerplugin.h

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#ifndef CUSTOMWIDGETPLUGIN_H
#define CUSTOMWIDGETPLUGIN_H

#include "selectdatewidget.h"
#include <QDesignerCustomWidgetInterface>

class SelectDateWidgetPlugin : public QObject, public QDesignerCustomWidgetInterface
{
     Q_OBJECT
     Q_INTERFACES(QDesignerCustomWidgetInterface)

   public:
     SelectDateWidgetPlugin(QObject *parent = 0);

     bool isContainer() const;
     bool isInitialized() const;
     QIcon icon() const;
     QString domXml() const;
     QString group() const;
         QString includeFile() const;
         QString name() const;
         QString toolTip() const;
         QString whatsThis() const;
         QWidget *createWidget(QWidget *parent);
         void initialize(QDesignerFormEditorInterface *core);

   private:
     bool initialized;
};

#endif



customwidgetplugin.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include "selectdatewidget.h"
#include "customwidgetplugin.h"

#include <QtPlugin>

SelectDateWidgetPlugin::SelectDateWidgetPlugin(QObject *parent)
    : QObject(parent)
{
     initialized = false;
}

void SelectDateWidgetPlugin::initialize(QDesignerFormEditorInterface * /* core */)
{
     if (initialized)
        return;

     initialized = true;
}

bool SelectDateWidgetPlugin::isInitialized() const
{
     return initialized;
}

QWidget *SelectDateWidgetPlugin::createWidget(QWidget *parent)
{
        SelectDateWidget *x = new SelectDateWidget(parent);
    return x;
}

QString SelectDateWidgetPlugin::name() const
{
        return "SelectDateWidget";
}

QString SelectDateWidgetPlugin::group() const
{
   return "Display Widgets [Examples]";
}

QIcon SelectDateWidgetPlugin::icon() const
{
     return QIcon();
}

QString SelectDateWidgetPlugin::toolTip() const
{
     return "";
}

QString SelectDateWidgetPlugin::whatsThis() const
{
     return "";
}

bool SelectDateWidgetPlugin::isContainer() const
{
     return false;
}

QString SelectDateWidgetPlugin::domXml() const
{
     return "<widget class=\"SelectDateWidget\" name=\"Select Date\">\n"
            " <property name=\"geometry\">\n"
            "  <rect>\n"
            "   <x>0</x>\n"
            "   <y>0</y>\n"
            "   <width>125</width>\n"
                    "   <height>24</height>\n"
                "  </rect>\n"
                " </property>\n"
                " <property name=\"toolTip\" >\n"
                "  <string>The current time</string>\n"
                " </property>\n"
                " <property name=\"whatsThis\" >\n"
                "  <string>The analog clock widget displays "
                "the current time.</string>\n"
                " </property>\n"
                "</widget>\n";
}

QString SelectDateWidgetPlugin::includeFile() const
{
    return "selectdatewidget.h";
}

Q_EXPORT_PLUGIN2(customwidgetplugin, SelectDateWidgetPlugin)



selectdatewidget.h

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#ifndef SELECTDATEWIDGET_H
#define SELECTDATEWIDGET_H

#include <QWidget>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>
#include <Qt>
#include <QtDesigner/QDesignerExportWidget>

class QDESIGNER_WIDGET_EXPORT SelectDateWidget : public QWidget
{
        public:
                SelectDateWidget(QWidget *parent=0);
        private:
                QHBoxLayout hboxLayout;
                QLabel *label;
                QLineEdit *lineEdit;

};

#endif



selectdatewidget.cpp

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "selectdatewidget.h"


SelectDateWidget::SelectDateWidget(QWidget *parent)
        : QWidget(parent)
{
        QHBoxLayout *hboxLayout = new QHBoxLayout(this);
        hboxLayout->setSpacing(0);
        hboxLayout->setContentsMargins(0,0,0,0);
        lineEdit = new QLineEdit(parent);
    lineEdit->setObjectName(QString::fromUtf8("lineEdit"));
    QSizePolicy sizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
    sizePolicy.setHorizontalStretch(0);
    sizePolicy.setVerticalStretch(0);
    sizePolicy.setHeightForWidth(lineEdit->sizePolicy().hasHeightForWidth());
    lineEdit->setSizePolicy(sizePolicy);

        hboxLayout->addWidget(lineEdit);

        label = new QLabel(parent);
        label->setObjectName(QString::fromUtf8("label"));
        label->setMinimumSize(QSize(24, 24));
        label->setPixmap(QPixmap());
        hboxLayout->addWidget(label);
}



selectdatewidget.pro

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
TEMPLATE = app
TARGET =
DEPENDPATH += .
INCLUDEPATH += .
TEMPLATE    = lib
CONFIG      += designer plugin debug_and_release
target.path = $$[QT_INSTALL_PLUGINS]/designer
INSTALLS += target

# Input
HEADERS += selectdatewidget.h \
                   customwidgetplugin.h
SOURCES += selectdatewidget.cpp \
                   customwidgetplugin.cpp

This post has been edited 6 times, last edit by "leoclog" (Apr 11th 2008, 8:25pm)

  • Go to the top of the page

Messenger

Intermediate

Posts: 325

Location: Lt

2

Friday, April 11th 2008, 6:54am

RE: Why does my plugin widget not show?

I think

Source code

1
2
3
4
5
6
7
8
9
10
11
class QDESIGNER_WIDGET_EXPORT SelectDateWidget : public QWidget
{
    Q_OBJECT // without this meta object system will function wrong.
        public:
                SelectDateWidget(QWidget *parent=0);
        private:
                QHBoxLayout hboxLayout;
                QLabel *label;
                QLineEdit *lineEdit;

};
Fighting fire with fire.
  • Go to the top of the page

3

Friday, April 11th 2008, 8:23pm

RE: Why does my plugin widget not show?

Hi Messenger,

Thank you very much. It has done the trick. I've been staring at the code for ages and just overlooked the macro.

Cheers,

Leo
  • Go to the top of the page

Rate this thread