PDA

View Full Version : EXtend functionality of QListWidget by making a plugin and use it in designer?



Sisyfos
13th December 2006, 10:41
Hi All
i have made a plugin for designer and it is showing in designer and i can use it only problem is that none of the propertys typical for QListwidget is visible in designer even though i did let my class subclass QListwidget. It is only the baseclass QWidget propertys that is accesible which means that i cant access a lot of the propertys that is present in QListWidget.

Now! is this not possible to achive? it seems to me it must be possible since they can make QT3plugins visible and usable in designer with all the propertys visible.

I will post my code now and see if someone can tell me if it is possible and if maybe i have done something wrong. now the only thing i have donee is to add a variable of the type QDate to the QListView but this was only so that i could figure out how the plugin was made. I am going to add more functions if i get it to show up as an extended QListWidget in Designer

dateViewList.h defining the class dateViewList and letting it subclass QListWidget


#ifndef DATEVIEWLIST_H
#define DATEVIEWLIST_H
#include <QListView>
#include <QDate>
#include <QObject>
#include <QWidget>
#include <QtDesigner/QDesignerExportWidget>
#include <QListWidget>
#include <QObject>


class QDESIGNER_WIDGET_EXPORT dateViewList : private QListWidget {

Q_OBJECT


public :
dateViewList(QWidget *parent );

public:
void setDate(QDate otherDate);


private:
QDate displayDate;


};
#endif



Implementing Class dateListView.cpp

#include "dateViewList.h"
#include <QDate>
#include <qdatetime.h>
#include <qwidget.h>
#include<QtGui>



dateViewList:: dateViewList(QWidget *parent ){


}

void dateViewList :: setDate(QDate otherDate){

this->displayDate = otherDate;

}

Defining customwidgetplugin.h


#ifndef CUSTOMWIDGETPLUGIN_H
#define CUSTOMWIDGETPLUGIN_H
#include <QDesignerCustomWidgetInterface>
#include <QtPlugin>
#include <QListWidget>

class extendedListWidgetPlugin : public QObject , public QDesignerCustomWidgetInterface
{

Q_OBJECT
Q_INTERFACES(QDesignerCustomWidgetInterface)

public: extendedListWidgetPlugin(QWidget *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;
QListWidget *createWidget(QWidget *parent);
void initialize(QDesignerFormEditorInterface *core);

private:
bool initialized;
};

#endif

implementing customwidgetplugin.cpp


#include "dateViewList.h"
#include <string>
#include <qstring.h>
#include <qobject.h>
#include <qwidget.h>
#include "customwidgetplugin.h"
#include <QtPlugin>
#include <qstringlist.h>
#include <QListWidget>



extendedListWidgetPlugin :: extendedListWidgetPlugin(QWidget *parent){

initialized = false;

}

void extendedListWidgetPlugin :: initialize(QDesignerFormEditorInterface * /* core */)

{
if (initialized)
return;

initialized = true;
}

QListWidget *extendedListWidgetPlugin :: createWidget(QWidget *parent)
{
return new dateViewList(parent);
}


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

QString extendedListWidgetPlugin::name() const
{
return "bikeDateList";
}

QString extendedListWidgetPlugin::group() const
{
return "Display Widgets [PLUGINS]";
}

QIcon extendedListWidgetPlugin :: icon() const
{
return QIcon("./hart.jpg");
}

QString extendedListWidgetPlugin :: toolTip() const
{
return "DateViewList";
}

QString extendedListWidgetPlugin :: whatsThis() const
{
return "Special widget for making Calender";
}

bool extendedListWidgetPlugin::isContainer() const
{
return true;
}

QString extendedListWidgetPlugin :: domXml() const
{
return "<widget class=\"dateViewList\" name=\"bikeDateList\">\n"
" <property name=\"geometry\">\n"
" <rect>\n"
" <x>0</x>\n"
" <y>0</y>\n"
" <width>100</width>\n"
" <height>100</height>\n"
" </rect>\n"
" </property>\n"
" <property name=\"toolTip\" >\n"
" <string>date Holder</string>\n"
" </property>\n"
" <property name=\"whatsThis\" >\n"
" <string>dateViewList holds property of the date "
"and functions to manipulate the list</string>\n"
" </property>\n"
"</widget>\n";
}

QString extendedListWidgetPlugin ::includeFile() const
{
return "dateViewList.h";
}

Q_EXPORT_PLUGIN2(customwidgetplugin , extendedListWidgetPlugin)




I understand i may not be able to set the extra attributes and variables i add to my class in designer but all the standard things like frame and stuff that is present in a ordinary QListWidget should at least be accessible in my plugin.

Anyone familliar with plugins?
ALL thoughts are Welcome exept for ppl loking for telemarket agencies!!

Cheers

e8johan
13th December 2006, 10:47
Just change this line:


class QDESIGNER_WIDGET_EXPORT dateViewList : private QListWidget {

to:


class QDESIGNER_WIDGET_EXPORT dateViewList : public QListWidget {

That aught to do it.

Sisyfos
13th December 2006, 13:54
unfortunatly that did'nt do it. the properties for QFrame and QabstractScrollarea and more are still not visible in designer. I will attach two screenshots to better explain the situation. in the customwidget screenshot i have added a custom widget and marked it for editing so that u can see the properties available for editing in the property editor.In the qtwidget screenshot i have done the same but with a ordinary QListWidget.

confused.......

wysota
13th December 2006, 16:13
dateViewList:: dateViewList(QWidget *parent ){}
You're not calling the base class (QListWidget) constructor.

Should be:


dateViewList:: dateViewList(QWidget *parent ) : QListWidget(parent){}

Sisyfos
13th December 2006, 17:03
I changed the dateListView.cpp to the following...BUT i am still not able to edit all the propertys of a QListWidget in Designer.





dateViewList :: dateViewList( QWidget* parent )
: QListWidget(parent)
{
}


So i am wondering is this part right in the customwidgetplugin.cpp

QListWidget *createWidget(QWidget*parent){returnnewdateListWid get()
};
Or should it be

QWidget* createWidget(QWidget *parent){return new dateListWidget()}
Or even

dateListView* createWidget(QWidget *parent){return new dateListWidget() }

Sisyfos
13th December 2006, 17:29
or is this all to do with the propertyEditor?
QDesignerFormEditorInterface :: propertyEditor ()

Is this what i somehow have to incorporate in my plugin?

wysota
13th December 2006, 19:55
So i am wondering is this part right in the customwidgetplugin.cpp

It should be

QWidget* createWidget(QWidget *parent){return new dateListWidget(parent);}

I suggest you take a look at an example of making a Qt Designer plugin that comes with Qt docs.

Sisyfos
13th December 2006, 21:56
Oh! i have read them time and time again!
The plugin is showing in designer so in that way i have done exactly as far as the example in the documentation takes me. But i have read numerous post, (on this FORUM and others. Here is onehttp://www.qtforum.org/thread.php?threadid=16072&hilight=Q+PROPERTY), that is asking exactly what i am asking. The problem is that none of the posts have any replies in them.
So i am starting to think it is not possible.
I think that it is only possible to edit the properties of the base class QWidget even though the documentation vaguely suggests that it is supposed to be possible to make the properties editable in designer by declaring Q_PROPERTY() in the class declaration.
SO if someone can prove me wrong i will jump with joy.

Sisyfos
13th December 2006, 22:39
check this one out for instance http://www.qtforum.org/thread.php?threadid=16072&hilight=Q+PROPERTY

wysota
13th December 2006, 22:53
Here is onehttp://www.qtforum.org/thread.php?threadid=16072&hilight=Q+PROPERTY), that is asking exactly what i am asking.
It's not exactly what you are asking. The poster there can't add any properties, and you can't see the ones which are already there.


So i am starting to think it is not possible.
I assure you it's possible.


I think that it is only possible to edit the properties of the base class QWidget even though the documentation vaguely suggests that it is supposed to be possible to make the properties editable in designer by declaring Q_PROPERTY() in the class declaration.
SO if someone can prove me wrong i will jump with joy.

Of course it's possible to add new properties and to see existing ones.

Here you go, you may base your widget on the code attached.

Sisyfos
14th December 2006, 00:08
I have not yet had the time to analyse exactly what i did wrong. I will have to look at that in the morning when my brain has regained capacity enough to grasp what u have done. BUT i just wanted to thank u so VERY much for taking the time to look at my sad example and point me in the right direction. I have tried for two days now to figure out what u did in a couple of minutes. So it is really a load of my shoulders. Again THX!

wysota
14th December 2006, 01:14
That's not my first Qt Designer plugin, I also learned on my mistakes while making my first plugins.

Sisyfos
15th December 2006, 11:48
That's not my first Qt Designer plugin, I also learned on my mistakes while making my first plugins.

I sort of figured it was not your first plugin :)
There were a number of problems with my code but most of all i had not understod the part where u call the base class constructor which seems to have caused some problems. But on thing i am wondering about is it really necessary to include the QCoreApplication. Cause it seems as if it was needed in my program but it is not clear from the documentation that it is needed in cases like this.
BUT then again i dont find the documentation to be very good it leaves a lot of guessing to be done.

Anyway i changed my code according to your example that u attached and now everything works just fine and i am happy as a clam.
I recommend all ppl that are having any problems with their plugins to take a look at the code that Wysota has attached. It is a good base to stand on.

wysota
15th December 2006, 12:52
But on thing i am wondering about is it really necessary to include the QCoreApplication. Cause it seems as if it was needed in my program but it is not clear from the documentation that it is needed in cases like this.
QCoreApplication is responsible for initialising plugins.


BUT then again i dont find the documentation to be very good it leaves a lot of guessing to be done.
That's your opinion :) According to me it just doesn't try to be smarter than the reader as some docs do.